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

Why doesn't this stay in place?

Asked by 8 years ago

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

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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)
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? UltraUnitMode 419 — 8y
0
game.Workspace.Part BlackJPI 2658 — 8y
Ad

Answer this question