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

Why doesn't this stay in place?

I'm trying to make a building system and whenever i move my mouse it gets closer to the camera and it glitches out. Help? ):

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Move:connect(function()
position = mouse.hit.p
game.Workspace.Part.Position = position
end)

1 answer

✓ Accepted answer

What is happening is that the mouse is hitting the brick you are moving, making it get closer and closer to you every time the event is fired.

There is a solution though, a target filter.

All you have to do is set mouse.TargetFilter to what ever object you want the mouse to ignore (including all of it's descendants):

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.TargetFilter = OBJECT_TO_IGNORE

mouse.Move:connect(function()
	position = mouse.hit.p
	game.Workspace.Part.Position = position
end)

2 comments

0

I did everything so it cant get any closer to the camera but it keeps doing it, i tried the player and the characters model. What should be Ignored?

0

game.Workspace.Part

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