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

How to make an object stop following your mouse when you press a button?

Asked by 3 years ago
Edited 3 years ago

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)

1 answer

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

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

0
@phxntxsmic i couldnt get that too work where do i add that ins and do i need to delete certain stuff Meerkatsrawesome 1 — 3y
1
What do you mean you couldn't get it to work? appxritixn 2235 — 3y
Ad

Answer this question