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.
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)
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)