Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is the model moving towards my screen everytime I move my mouse?

Ok so I got 2 parts that are grouped together and I managed to make them follow my mouse cursor, however whenever I move my mouse the model seems to be moving towards my screen every time I move my mouse and once it covers up my entire screen it goes back to land (or baseplate) and it would do this repeatedly. How do I prevent it from going to my screen?

Here is the script that makes the model follow my mouse cursor:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Part = game.Workspace.Model
local CurrentRot = 0

Mouse.Move:Connect(function()
	Part:SetPrimaryPartCFrame(CFrame.new(Mouse.Hit.p)*CFrame.Angles(0,math.rad(CurrentRot),0))
end)

Is there something wrong with the script or am I just missing something? Also I've tried making both of the part's CanCollide property to false.

Please help! Thanks!

1 answer

✓ Accepted answer

Super simple answer, the mouse position updates every time it moves to be on the model. Since you are repeatedly moving the model to the mouse at the same time, it becomes a loop of the model getting closer. To solve this, all you have to do is get the mouse to ignore the model. At the top of the script, add:

Mouse.TargetFilter = Part

to make the mouse ignore the model and its descendants.

1 comment

0

Wow XD Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.