Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

2 comments

0

Exactly what i needed, thanks!

0

No problem :)

This discussion is preserved as it was. New answers, comments, and votes are closed.