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

I need help with a script that makes a machine have a cooldown. [?]

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.

2 comments

0

Please tab your code. This is almost unreadable.

0

Is filtering enabled on? If so, click detectors act really weird. Try printing the player variable after line three. If it prints nil than that's your problem.

2 answers

✓ Accepted answer
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.

2 comments

0

I'm almost certain that wasn't his problem. But I would like to see what prints. This should work btw, but so should his. I don't think the code is the problem.

0

Oh, I see now. I take back my initial claim. Sorry about my doubt.

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.