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 GUI 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

The following part works fine but it wont stop following

here is my code currently:

local Player = game.Players.LocalPlayer
local HandTracer = workspace.HAND_TRACER
local mouse = Player:GetMouse()
local squishbutton = game.StarterGui.Human_GUI.Squish_button -- the button pressed

if Player.Team.TeamColor == BrickColor.new("New Yeller") then
    script.Parent.Parent.Enabled = true
    script.Parent.MouseButton1Click:Connect(function()
        if HandTracer.Transparency == 1 then
            HandTracer.Transparency = 0.65  
    mouse.TargetFilter = game.Workspace.HAND_TRACER

    while wait() do
        game.Workspace.HAND_TRACER.CFrame = CFrame.new(mouse.Hit.p)
        game.Workspace.HAND_TRACER.Orientation = Vector3.new(-90, 90, 0)
    end

        else
            HandTracer.Transparency = 1 
        end
    end)

end

if Player.Team.TeamColor == BrickColor.new("Black") then
script.Parent.Parent.Enabled = false
end

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

instead of doing

while wait() do

add in the " HandTracer.Transparency == 0.65 " condition; therefore making it

while wait() and HandTracer.Transparency == 0.65 do

this way it'll stop the loop if the hand is invisible

0
line 13* SPOOK_EXE 35 — 3y
0
Couldnt get it too work Meerkatsrawesome 1 — 3y
0
its not following the mouse anymore Meerkatsrawesome 1 — 3y
Ad

Answer this question