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

The script works only if the player spawns with the condition,but i want it to work every time, how?

Asked by
Echtic 128
5 years ago

This is the script:

wait()
local plr = game.Players.LocalPlayer
local magice = plr:WaitForChild("MagicEnergy")
local maxmagice = plr:WaitForChild("MaxMagicEnergy")


if magice.Value ~= maxmagice.Value then

    repeat

        wait(.5)
        magice.Value = magice.Value + 10
        wait(.5)

    until

    magice.Value == maxmagice.Value 


end

Like i said It works only if the player spawns with magice.Value being less than maxmagice.Value, but i need it to do the regeneration every time magice.Value is lower than maxmagice.Value

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

like this the script is executed only once. Try this:

wait()
local plr = game.Players.LocalPlayer
local magice = plr:WaitForChild("MagicEnergy")
local maxmagice = plr:WaitForChild("MaxMagicEnergy")

while true do
wait ()
if magice.Value ~= maxmagice.Value then

    repeat

        wait(.5)
        magice.Value = magice.Value + 10
        wait(.5)

    until

    magice.Value == maxmagice.Value 


end
end

While true do lets it run in a loop

0
Exactly what i needed, thanks! Echtic 128 — 5y
0
No problem :) MageMasterHD 261 — 5y
Ad

Answer this question