When I have my code in this format, it doesnt work. However if i take out the if condition for checking that the value is 0 it works. Im not sure why, hopefully one of you lovely people can figure it out
ticket = script.Parent debounce = 0 function onTouched(hit) if debounce == 0 then debounce = 1 local check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local user = game.Players:GetPlayerFromCharacter(hit.Parent) local stats = user:FindFirstChild("orbfolder") if stats ~= nil then local ticket = stats:FindFirstChild("orb1") if ticket.Value == 0 then ticket.Value = ticket.Value + 1 wait(5) debounce = 0 end else end end end end ticket.Touched:Connect(onTouched)
If the value you're referring to is TicketValue, then this is probably your problem.
1st time through:
lua
if ticket.Value == 0 then --Checks if its 0, true
ticket.Value = ticket.Value + 1 --Adds one
2nd time through:
lua
--Ticket value is now 1, not 0
if ticket.Value == 0 then --Checks if its 0, false
ticket.Value = ticket.Value + 1 --Wont add 1, because the prior statement was false.
When the function is fired again, the ticket value wont be 0. Its will be 1.
Therefor, the check for ticket.Value == 0
would come back as false, and the code after it ticket.Value = ticket.Value + 1
would never fire.
Also, I'd like to suggest using booleans instead of 0 and 1 for your debounces.
ie: ```lua Debounce = false
function Test() if not Debounce then --Same as saying "if Debounce == false" Debounce = true wait(10) Debounce = false end end ``` Hope this helped.