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

Why is the debounce messing up the script?

Asked by 10 years ago

So I'm trying to make a machine that can do several things, but only one at a time. I created a debounce using a boolvalue

All the scripts look generally like this (except the strings are different):

debounce = script.Parent.Value.Value

function tch(h)
    if not debounce then
        debounce = true
            else return end
    if (h.Parent.Name == "Espresso Beans") then
        script.Parent.Parent.Beans1.Transparency = 0
        script.Parent.Grind:Play()
        wait(1)
        script.Parent.Parent.Beans1.Transparency = 1
        script.Parent.Parent.Beans2.Transparency = 0
        wait(1)
        script.Parent.Parent.Beans2.Transparency = 1
        script.Parent.Parent.Beans3.Transparency = 0
        wait(1)
        script.Parent.Parent.Beans3.Transparency = 1
        h.Parent.Name = "Espresso Roast"
        debounce = false
end end

script.Parent.Touched:connect(tch)

I can run only one of the scripts only once, but after that they are all rendered useless (by the debounce) If I remove the debounce completely, it works.(But without the effects of the debounce that I want.) And when I test it, it doesn't give me an error. So my guess is that* line 19* is not doing what it's supposed to for some reason, please help me out.

2 answers

Log in to vote
1
Answered by
jobro13 980 Moderation Voter
10 years ago

I think this error is a very logical one to make. I made it myself too. It has to do with what the variables hold.

As you know, if you want to set the name of Workspace, you do game.Workspace.Name = "new name".In order to save this name to a variable, you use name = game.Workspace.Name. However, what happens if you now do name = "new name"? Does it change the name of game.Workspace, or does it change the contents of the variable name?

It actually changes the contents and does not set the name. Therefore, you want to create a "debounceTracker" and to set this, you use "debounceTracker.Value". Thus:

debounceTracker = script.Parent.Value -- This changed

function tch(h)
    if not debounceTracker.Value then -- thus debounceTracker.Value == false
        debounceTracker.Value = true
            else return end
    if (h.Parent.Name == "Espresso Beans") then
        script.Parent.Parent.Beans1.Transparency = 0
        script.Parent.Grind:Play()
        wait(1)
        script.Parent.Parent.Beans1.Transparency = 1
        script.Parent.Parent.Beans2.Transparency = 0
        wait(1)
        script.Parent.Parent.Beans2.Transparency = 1
        script.Parent.Parent.Beans3.Transparency = 0
        wait(1)
        script.Parent.Parent.Beans3.Transparency = 1
        h.Parent.Name = "Espresso Roast"
        debounceTracker.Value = false
end end

script.Parent.Touched:connect(tch)

0
It's having the same issue as before. :( orderman 15 — 10y
0
What exactly is going wrong then? This should work... jobro13 980 — 10y
0
It has something to do with the other scripts, when I use one of them, I can re-use that one as much as I want, but the other ones are completely useless after that. When I try to use the other ones it turns the value to true but doesn't go through the rest of the script. orderman 15 — 10y
Ad
Log in to vote
0
Answered by
Dummiez 360 Moderation Voter
10 years ago

You could try using a global debounce? It would work in a ServerScript, but not locally :P

_G.debounce = false

function tch(h)
    if not _G.debounce then
        _G.debounce = true
    if (h.Parent.Name == "Espresso Beans") then
        script.Parent.Parent.Beans1.Transparency = 0
        script.Parent.Grind:Play()
        wait(1)
        script.Parent.Parent.Beans1.Transparency = 1
        script.Parent.Parent.Beans2.Transparency = 0
        wait(1)
        script.Parent.Parent.Beans2.Transparency = 1
        script.Parent.Parent.Beans3.Transparency = 0
        wait(1)
        script.Parent.Parent.Beans3.Transparency = 1
        h.Parent.Name = "Espresso Roast"
        _G.debounce = false
end end end

script.Parent.Touched:connect(tch)

Answer this question