function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local Mana = Instance.new("IntValue") Mana.Name = "Mana" Mana.Value = 100 if Mana.Value>500 then Mana.Value = 500 end if Mana.Value<500 then Mana.Value ----------------i need help on this line. I'm trying to make the mana refill if its less than 500 by 10 end end game.Players.ChildAdded:connect(onPlayerEntered)
function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local Mana = Instance.new("IntValue") Mana.Name = "Mana" Mana.Value = 100 if Mana.Value>500 then Mana.Value = 500 end if Mana.Value<500 then Mana.Value = Mana.Value + 10 --Adding 10 to "Mana" everytime this statement runs. end end game.Players.ChildAdded:connect(onPlayerEntered)
This is doing what you asked for, however, I think your overall goal may need a lot more work in the future.
I wish you luck in finishing your idea!
EDIT: BlueTaslem
has a better answer as well as a more efficient way of accomplishing what you intend to do.
You want to increase by mana by ten there? (This is called incrementing by 10)
We set Mana.Value
to what Mana.Value
was + 10
:
Mana.Value = Mana.Value + 10;
Note that the "increase by ten but cap at 500" can be written as a single line without any if
s:
Mana.Value = math.min( 500, Mana.Value + 10 ); -- This replaces line 08 to 13 in the snippet you posted
That is, the lesser of 500
or increasing Mana.Value
by 10
.
Note also, however, that that work has to be done continuously. Right now are you just doing it when the player joins, which will not affects things later. It should be in a while
loop with some wait
.
Something like:
while wait(3) do -- Every three seconds . . . Mana.Value = math.min( 500, Mana.Value + 10 ); -- Recharge by ten end