I wrote a script to turn a value off for a while and then turn it back on, but it doesn't seem to be working. I have analyzed every line and I cannot find the error. Please help.
debounce = false function OnClicked(player) if debounce == false then debounce = true if player.TeamColor == script.Parent.Parent.Parent.Parent.Parent.TeamColor.Value then wait(0.1) script.Parent.BrickColor = BrickColor.new("Really black") script.Parent.Parent.Running.Value = false wait(119.9) script.Parent.BrickColor = BrickColor.new("Dark indigo") script.Parent.Parent.Running.Value = true debounce = false end end end script.Parent.ClickDetector.MouseClick:connect(OnClicked)
Nothing appears in output at all.
local debounce = false function OnClicked(player) if debounce == false then print("Passed first If Statement") debounce = true if player.TeamColor == script.Parent.Parent.Parent.Parent.Parent.TeamColor.Value then print("Passed second If Statement") wait(0.1) script.Parent.BrickColor = BrickColor.new("Really black") script.Parent.Parent.Running.Value = false wait(119.9) script.Parent.BrickColor = BrickColor.new("Dark indigo") script.Parent.Parent.Running.Value = true end print("Setting debounce to false") debounce = false end end script.Parent.ClickDetector.MouseClick:connect(OnClicked)
Try this. I just moved the 'debounce = false' to the end of the first if statement, so that if the second if statement isn't met, it will again set the debounce (cooldown) to false. Also made debounce 'local'.
Tip: If you want to find where the script fails, use print(), like what I did here.
I don't know if there are more errors in the script, but I'm sure that this will fix your cooldown problem.
Nothing seems wrong. Check in workspace like: - Is the script place in the correct place? - Is this script a server script or a local script - Is Disabled off?