Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script wont add to int value in folder?

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)

1 answer

✓ Accepted answer

If the value you're referring to is TicketValue, then this is probably your problem.

1st time through:

if ticket.Value == 0 then --Checks if its 0, true
ticket.Value = ticket.Value + 1 --Adds one

2nd time through:

--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:

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.

3 comments

0

So basically, your function only works if they have no tickets. Oh and about the Boolean debounces, its just easier to read that way. Really nothing wrong with what you were doing. 

0

It worked now when i copied and pasted what i put in here to there. Weird.

0

Glad to help

This discussion is preserved as it was. New answers, comments, and votes are closed.