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

can anyone help me on this script?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
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)
0
Rephrase the question, please? RedCombee 585 — 10y
0
What Red Said i'm completely confused! Mauvn 100 — 10y

2 answers

Log in to vote
0
Answered by
Necrorave 560 Moderation Voter
10 years ago
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.

Ad
Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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 ifs:

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

Answer this question