How to make part following mouse not go above on the Y axis and only stays on the ground?

Hello, like the title says, I had part of a script that makes a part follow the mouse whenever it is active. The problem is whenever the player looks upwards, the part just disappears into the sky as the mouse’s position says that it’s at a very high altitude. How can I prevent it from going up and only stay on ground level at all times, and would I need to check for ground level if I wanna achieve such result?

a = game:GetService("RunService").RenderStepped:Connect(function()
	part.Position = game.Players.LocalPlayer:GetMouse().Hit.Position 
	mouse.TargetFilter = part
end)

Hello, maybe you can try this code.

 a = game:GetService("RunService").RenderStepped:Connect(function()
	local mouse = game.Players.LocalPlayer:GetMouse()
	if mouse.Target then
		part.Position = mouse.Hit.Position
	end
	mouse.TargetFilter = part
end)
1 Like

My bad, I kinda got bored of the project so I just left it there but your solution works

what project are you making hmm…

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