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

Why don't these variables update properly?

Asked by 7 years ago
Edited 7 years ago

I have two variables, done and triggered. Both update momentarily as they are updated in the code, but immediately after they are reset. Any ideas on what's happening? I've already tried making them their own separate values, but the same thing happens.

01local parPar = script.Parent.Parent
02 
03local posX = parPar.Position.X
04local posY = parPar.Position.Y
05local posZ = parPar.Position.Z
06 
07local done = false
08local triggered = false
09 
10local function timer()
11    wait(1.5)
12    local done = true
13end
14 
15script.Parent.Touched:connect(function(hit)
View all 36 lines...

EDIT: Forgot to mention that no errors come up in the output.

1 answer

Log in to vote
0
Answered by 7 years ago

Your problem is you are not actually updating the variables you want to update. More specifically, you are using "local" in timer() to set done equal to true. This is creating a new variable called done only accessible in that scope. Same with your triggered variable, you are just re creating it.

All you have to do is just remove the local from line 12 and 19, it will instead just change the variable you had already defined instead of defining a new one for that scope.

It is "resetting" itself, because after that code in connect() and timer() are finished, it is still using the other variables you made at the beginning of the script because the other variables are now out of scope.

Hope this helped.

0
Thank you! AvatarAang400 35 — 7y
0
No problem :) Gamprofwiesonel 31 — 7y
Ad

Answer this question