Part clipping through ground

Hi, so the script is simple, it makes a part follow the player’s mouse and moves the part every frame, how do I make the part not clip through the ground?

r.RenderStepped:Connect(function()
	m.TargetFilter = c
	
	local p = m.Hit.p
	
	local x,y,z = math.floor(p.X),math.floor(p.Y),math.floor(p.Z)
	
	c.Position = Vector3.new(x,y,z)
end)
r.RenderStepped:Connect(function()
	m.TargetFilter = c
	
	local p = m.Hit.p
	
	local x,y,z = math.floor(p.X), p.Y + c.Size.Y / 2,math.floor(p.Z)
	
	c.Position = Vector3.new(x,y,z)
end)

Also it might be a good idea to use more descriptive variable names, especially if you do something more complicated.

Thank you it worked, but I prefer short and simple scripts.

1 Like