I am making an imagebutton in the player's ScreenGui that fires a remote event for 10 seconds, then has a 20 second cooldown time. When I click the button once, it works fine, but if I click the button multiple times, the function and the timer I made restart as well. Is there some way to prevent the button from receiving user input while its function is still running? Here is my code to give you an idea of what I mean. Inside my imagebutton is a textlabel and a local script. The following code is from the localscript.
script.Parent.MouseButton1Click:Connect(function()
print("Button was clicked.") script.Parent.Active = false script.Parent.Selectable = false game.ReplicatedStorage.STOPbutton:FireServer() for i = 10, 0, -1 do script.Parent.TextLabel.Text = i wait(1) end for i = 20, 1, -1 do script.Parent.TextLabel.TextColor3 = Color3.new(0,0,0) script.Parent.TextLabel.Text = i wait(1) end script.Parent.TextLabel.Text = "STOP!" script.Parent.Active = true script.Parent.Selectable = true script.Parent.TextLabel.TextColor3 = Color3.new(255,255,255)
end)
Like that?
script.Parent.MouseButton1Click:Connect(function() if script.Parent.Active then print("Button was clicked.") script.Parent.Active = false script.Parent.Selectable = false game.ReplicatedStorage.STOPbutton:FireServer() for i = 10, 0, -1 do script.Parent.TextLabel.Text = i wait(1) end for i = 20, 1, -1 do script.Parent.TextLabel.TextColor3 = Color3.new(0,0,0) script.Parent.TextLabel.Text = i wait(1) end script.Parent.TextLabel.Text = "STOP!" script.Parent.Active = true script.Parent.Selectable = true script.Parent.TextLabel.TextColor3 = Color3.new(255,255,255) end end)