Im experimenting with a script that goes through multiple phases. The phases are announced via a phase value. Heres the script:
script.Parent:WaitForChild("Phase") local phase = script.Parent.Phase wait(5) script.Parent.Phase.Value = script.Parent.Phase.Value + 1 phase.Changed:connect(function() script.Parent.Phase.Value = script.Parent.Phase.Value + 1 end)
The value changes to "1" on line 5 like it should, however does not changed to "2" when the Value Changed function fires.
All help is appreciated
Below is the correct way of doing this, there's also an explanation of what you were doing wrong if you were wondering.
local phase = script.Parent:WaitForChild("Phase"); wait(5); phase.Changed:connect(function() wait(); -- small warning here, this event may loop phase.Value = phase.Value +1; end) phase.Value = phase.Value + 1;
You seem to be checking for the Changed
event after you make the value go up one. So to solve your problem you would need to put the function before you make the value go up by one. I've also cleaned up your code to have less lines, since you didn't need to have some of your code in a certain order.
For example,
script.Parent:WaitForChild("Phase") local phase = script.Parent.Phase
You could make these lines of code into one.
local phase = script.Parent:WaitForChild("Phase");
Don't forget to mark this as solved and as the correct answer if this works!