So im trying to make a part follow the mouse of the player but when i do not move my mouse constantly it goes on itselfe and this repeats until it hits my cam
thats the code i used how can i change that
wait(2) local Player = game:GetService("Players").LocalPlayer local Part = game.ReplicatedStorage.Part local mouse = Player:GetMouse() while wait() do local Loc = mouse.Hit print(Loc) Part.Parent = workspace Part.CFrame = Loc+Vector3.new(0,.5,0) Part.Orientation = Vector3.new(0,0,0) end
Hey there! This has to do with Mouse.TargetFilter
. Essentially, your mouse is hitting the coordinate point on top of the brick over and over again, which is what causes this effect.
To make this have the behavior you want, you need to ignore the part in question when deciding what coordinate point the mouse is hitting.
You can do this by simply modifying the mouse's TargetFilter
.
wait(2) local Player = game:GetService("Players").LocalPlayer local Part = game.ReplicatedStorage.Part local mouse = Player:GetMouse() mouse.TargetFilter = Part while wait() do local Loc = mouse.Hit print(Loc) Part.Parent = workspace Part.CFrame = Loc+Vector3.new(0,.5,0) Part.Orientation = Vector3.new(0,0,0) end
In this revised code we tell the hit detection to completely ignore this part.
TargetFilter
can be a BasePart
, Model
, or anything of the sort. All descendants
of TargetFilter
will also be ignored.