Im trying to have an object follow the mouse when i press a guibutton button and have it stop following it when i press the same button how can you get it to stop following it
here is my code currently
1 mouse.TargetFilter = game.Workspace.HAND_TRACER
2
3 while wait() do
4 game.Workspace.HAND_TRACER.CFrame = CFrame.new(mouse.Hit.p)
You need a boolean variable to determine when the "HAND_TRACER" object should follow the player's mouse.
local follow = false -- this is the boolean variable local mouse = game.Players.LocalPlayer:GetMouse() mouse.TargetFilter = workspace:WaitForChild("HAND_TRACER") GUI_OBJECT.MouseButton1Click:Connect(function() -- Replace GUI_OBJECT with your text/image button follow = not follow -- toggle end) while wait() do if follow then -- if the object should follow the mouse cursor workspace.HAND_TRACER.CFrame = CFrame.new(mouse.Hit.p) end end
Note: "workspace" and "game.Workspace" point to the same location