Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script wont add to int value in folder?

Asked by 5 years ago

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

Log in to vote
0
Answered by
Psudar 882 Moderation Voter
5 years ago

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.

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.  Psudar 882 — 5y
0
It worked now when i copied and pasted what i put in here to there. Weird. spot6003 64 — 5y
0
Glad to help Psudar 882 — 5y
Ad

Answer this question