Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Nep_Ryker 131
5 years ago

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

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago

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.

0
Wow XD Thanks Nep_Ryker 131 — 5y
Ad

Answer this question