Untitled

 avatar
unknown
plain_text
2 years ago
2.8 kB
6
Indexable
**Soil Placement**

Local Script inside a tool named "Soil"

```
localPlayer = game.Players.LocalPlayer
mouse = localPlayer:GetMouse()

local tool = script.Parent
local SoilFloors = game.Workspace.SoilFloors

local ReplicatedStorage = game:GetService("ReplicatedStorage")

function DummySoil()
	PreviewSoil = ReplicatedStorage.SoilPatch:Clone()
	PreviewSoil.Name = "PreviewSoil"
	PreviewSoil.Parent = game.Workspace
	PreviewSoil.Transparency = 0.5

	heightOffset = Vector3.new(0, PreviewSoil.Size.Y / 2, 0)

	mouse.TargetFilter = PreviewSoil

	mouse.Move:Connect(function()
		PreviewSoil.Position = mouse.Hit.p + heightOffset
	end)
end

function DummySoilRemover()
	PreviewSoil:Destroy()
end

tool.Activated:Connect(function()
	for i, floor in SoilFloors:GetChildren() do
		if mouse.Target == floor then

			local PlacedSoil = PreviewSoil:Clone()
			PlacedSoil.Name = "PlacedSoil"
			PlacedSoil.Parent = floor
			PlacedSoil.Transparency = 0
			PlacedSoil.Anchored = true

			PlacedSoil.Position = mouse.Hit.Position + heightOffset
			
			tool:Destroy()
			PreviewSoil:Destroy()
			print("yes")
		end
	end
end)

tool.Equipped:Connect(DummySoil)
tool.Unequipped:Connect(DummySoilRemover)
```




**Sugar Plant Placement**

Local Script inside a tool named "SuagrPlant"

```
localPlayer = game.Players.LocalPlayer
mouse = localPlayer:GetMouse()

local tool = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SugarPlantModel = game.ReplicatedStorage.SugarPlantModel
local SugarPlantBranch = game.ReplicatedStorage.SugarPlantModel.Branch

heightOffset = Vector3.new(0, SugarPlantBranch.Size.Y / 2, 0)

tool.Activated:Connect(function()
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {localPlayer.Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	
	local unitRay = mouse.UnitRay
	local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * 500, raycastParams)


	if raycastResult then
		local RayInstance = raycastResult.Instance
		
		if RayInstance.Name == "PlacedSoil" then
			
			local PlacedSoilGui = RayInstance:FindFirstChild("BillboardGui")
			PlacedSoilGui:FindFirstChild("TextLabel").Visible = true

			print("uh")
			
			tool:Destroy()

			wait(6)

			PlacedSoilGui:FindFirstChild("TextLabel").Visible = false
			
			local PlacedSugarPlant = SugarPlantModel:Clone()
			PlacedSugarPlant.Name = "PlacedSugarPlant"
			PlacedSugarPlant.Parent = RayInstance

			for i, object in ipairs(PlacedSugarPlant:GetChildren())  do
				if object:IsA("MeshPart") then
					object.Transparency = 0
					object.Position = raycastResult.Position + heightOffset
				end
			end
		end
	end
end)
```
Editor is loading...