How to stop part from bugging out with mouse script

Here’s my code:

local part1 = game.Workspace.LookAtMouseTest
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Move:Connect(function()

    part1.CFrame = CFrame.lookAt(part1.Position, mouse.Hit.p)

end)

I want the part not to spaz out when the mouse touches it, but I’m not exactly sure how to stop that from happening.

Oh, and I attached a video of what the problem is, it should clear up the main problem.

Ignore parts with mouse.TargetFilter

local part1 = game.Workspace.LookAtMouseTest
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Move:Connect(function()
	mouse.TargetFilter = part1
	part1.CFrame = CFrame.lookAt(part1.Position, mouse.Hit.p)
end)

Tysm! never even knew about TargetFilter. I’m learnin to get better with Mouse stuff tho, thanks for the help.

If you want something smoother

local part1 = game.Workspace.LookPart
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local RS = game:GetService("RunService")

RS.RenderStepped:Connect(function()
	mouse.TargetFilter = part1
	part1.CFrame = part1.CFrame:lerp(CFrame.lookAt(part1.Position,mouse.Hit.p),0.05)
end)

Use RenderStepped because it might be a little weird with :lerp

1 Like

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