Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

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.

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.