how do i make a loop script where i can enable and disable the loop from gui buttons?
COMMUNITY QUESTION
how to make a looping button that can be turned on and off?
1 answer
--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
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
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.