Mouse.hit not working correctly [SOLVED]

SOLUTION: mouse.TargetFilter = MOVING OBJECT
THANK YOU ICEDREEM
Hi, everyone! I’m trying to make a placement system for my game, but I’ve ran into a problem. Every time I test it the object keeps coming towards me when I don’t move my mouse. I took a video to show you what’s happening:

.
What I’ve tried:
I heard that it’s better to use Mouse.UnitRay but I tried this and couldn’t figure it out, I’d totally be open to switching to that if it’s better.
Extra info:
-I’m using MOUSE.HIT for this
-I’m using a local script
-I took a break of Lua for a while, and forgot a lot about it. Please let me know if you see anything that looks off or needs to be fixed.
-My script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local runService = game:GetService("RunService")
for i,v in pairs(script.Parent.ScrollingFrame:GetChildren()) do
	if v:IsA("TextButton") then
	v.MouseButton1Down:Connect(function()
			local building = v.Name
			local prev = game.ReplicatedStorage.Buildings:WaitForChild(building):Clone()
			prev.Material = "Neon"
			prev.BrickColor = BrickColor.new("Lime green")
			prev.Anchored = true
			prev.CanCollide = false
			prev.Parent = workspace
			runService.RenderStepped:Connect(function()
				wait(.1)
				local mousePos = mouse.Hit.Position
					
			print(mousePos)
				prev.Position = mousePos
			
				
			end)
		end)
		end
end

If you need any more information please don’t hesitate to ask.
Thanks in advance for your help. Have a great rest of your day.

Blacklist the object you are placing on the mouse and use ray casting instead of raw mouse.hit.position

1 Like

mouse.TargetFilter = prev
In case anyone is unsure of the solution.

1 Like