I have a script where players touch a part with tools. I want to add a debounce so the player has to wait before giving it another tool. Can anyone help me with this?
oats = 0 print(oats) local Allowed = false function tch(h) if (h.Parent.Oats.Name == "Oats") then oats = oats + 1 h.Parent:Destroy() print(oats) end end script.Parent.Touched:connect(tch) local Allowed = false function give(dough) if Allowed == true then local y = dough.Backpack local z = game.Lighting["Handful of Oats"] z:Clone().Parent = y oats = oats - 1 Allowed = false end end function onClicked() if oats > 0 then Allowed = true end end script.Parent.ClickDetector.MouseClick:connect(give) script.Parent.ClickDetector.MouseClick:connect(onClicked)
oats = 0 print(oats) script.Parent.Touched:Connect(function(h) if h.Parent.Oats.Name == "Oats" then oats = oats + 1 h.Parent:Destroy() print(oats) end end) local Debounce = false script.Parent.ClickDetector.MouseClick:Connect(function(dough) if oats > 0 and Debounce == false then Debounce = true local y = dough.Backpack local z = game.Lighting["Handful of Oats"] --ServerStorage recommended over lighting! z:Clone().Parent = y oats = oats - 1 wait(1) --can't do it again for 1 second Debounce = false end end)