So basically, I'm trying to make it so when a button is pressed, the smoke turns on, That part works, however, I'm trying to make it so you can disable it with a debounce. If you can, please help.
local enabled = false local debounce = false local Model = script.Parent.Parent.Parent.gas script.Parent.ClickDetector.MouseClick:Connect(function() for i,v in pairs (Model:GetChildren()) do if not debounce then if enabled == false then v.Smoke.Enabled = true wait(3) debounce = false if v.Smoke.Enabled == true then v.Smoke.Enabled = false end end end end end)
You need to set the debounce to true because after the check is completed you only want it to work only once, right? If you want it to only work once then set the debounce to true after the debounce check because other iterations will check the if statement again and the debounce will be true, making it not pass the debounce check.
local enabled = false local debounce = false local Model = script.Parent.Parent.Parent.gas script.Parent.ClickDetector.MouseClick:Connect(function() for i,v in pairs (Model:GetChildren()) do if not debounce then debounce = true if enabled == false then v.Smoke.Enabled = true wait(3) debounce = false if v.Smoke.Enabled == true then v.Smoke.Enabled = false end end end end end)
local enabled = false local debounce = false local Model = script.Parent.Parent.Parent.gas script.Parent.ClickDetector.MouseClick:Connect(function() for i,v in pairs (Model:GetChildren()) do if debounce == false then if enabled == false then debounce = true v.Smoke.Enabled = true wait(3) debounce = false if v.Smoke.Enabled == true then v.Smoke.Enabled = false end end end end end)