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

how to make a looping button that can be turned on and off?

Asked by 6 years ago

how do i make a loop script where i can enable and disable the loop from gui buttons?

0
First make a loop in a (Normal) script located wherever you want. Then when you click on the buttons you would use a RemoteEvent to toggle a variable in the script that would control if the loop will go or not. papasherms 168 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
--LocalScript
local wfc=game.WaitForChild
local re=wfc(game:GetService("ReplicatedStorage"),"RemoteEvent")
local button --TheButtonYourPressing

button.MouseButton1Click:Connect(function()
    re:FireServer("toggle")
end)

--ServerScript
local wfc=game.WaitForChild
local var=false
local re=wfc(game:GetService("ReplicatedStorage"),"RemoteEvent")

re.OnServerEvent:Connect(function(plr,func,...)
    local args={...}
    if func=="toggle" then
        var=not var
    end
end)

while var do
    wait()
    --Do Whatever you want the loop to do.
end
Ad

Answer this question