How would you make a tool place only on the ground, and not in any other direction?

I currently have a tool which places itself in the direction of the player’s mouse.

My issue is that I can’t figure out how to make it so that the tool places only on the ground, and not on walls, ceilings or anywhere else.

I looked through some posts, but didn’t really find anything that helpful.

Here is an example of my code:

--**Local Script**

plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
tool = script.Parent

tool.Activated:Connect(function()
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local RemoteFunction = ReplicatedStorage.SoilPlacement:WaitForChild("ClientToServer")

	if RemoteFunction then
		RemoteFunction:InvokeServer(mouse.Hit.Position)
	end
end)
--**Server Script**

local tool = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteFunction = ReplicatedStorage.SoilPlacement:WaitForChild("ClientToServer")

use = true

RemoteFunction.OnServerInvoke = function(player, mouse_pos)
	if use then
		use = false
			local Soil = tool.Handle:Clone()
			Soil.Parent = game.Workspace
			Soil.Name = "SoilPatch"
			Soil.CanCollide = true
			Soil.Anchored = true

			Soil.Size = tool.Handle.Size
			Soil.Position = mouse_pos
		use = true
	end
end

Any and all help is appreciated

You could maybe use raycast to make sure the tool can only place itself on what you define as ground in your game

I have found the solution. Turns out you can just use mouse.target to check if the player’s mouse clicks on a specific part.

You can read more here:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.