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

Why wont this script regen my custom energy?

Asked by 5 years ago
01local RegenSpeed = 0.25
02 
03 
04local energylvl = script.Parent.Energy
05local energyMAX = script.Parent.EnergyMAX
06 
07 
08while true do
09    local energylvl = script.Parent.Energy
10    local energyMAX = script.Parent.EnergyMAX
11    local RegenRate = script.Parent.RegenRate
12    while energylvl.Value < energyMAX.Value do
13        energylvl.Value = energylvl.Value + RegenRate
14        wait(RegenSpeed)
15    end
16    end
0
I think you forgot to do RegenRate.Value on line 13, or add .Value to the end of line 11 lucas4114 607 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago
01local RegenSpeed = 0.25
02 
03 
04 local energylvl = script.Parent.Energy
05 local energyMAX = script.Parent.EnergyMAX
06 local RegenRate = script.Parent.RegenRate
07 
08 
09while true do
10    if energylvl.Value < energyMAX.Value then--make it an if statement instead, not much more you can change
11        energylvl.Value = energylvl.Value + RegenRate.Value--you forgot to tell it to add the value of the regenrate
12        wait(RegenSpeed)
13    end
14    end
0
it still doesnt work, I put a print after wait and it doesnt show. No errors though... tightanfall 110 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

After while true do add a wait so it doesnt crash

0
it doesnt crash due to the wait(RegenSpeed) tightanfall 110 — 5y

Answer this question