Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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.

0
Please tab your code. This is almost unreadable. AZDev 590 — 8y
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. User#11440 120 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago
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.

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. User#11440 120 — 8y
0
Oh, I see now. I take back my initial claim. Sorry about my doubt. User#11440 120 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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?

Answer this question