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

How to make a system that after each level your health gets one more? [unsolved]

Asked by 8 years ago
Edited 8 years ago

Hello I tried to make a script that when you level up you gets one more maxhealth. PROBLEM: if player has more xp it goes example: you are 4 level gets 1000 xp and now level 7 you skiped level 5,6 so it means you didn't get that + 1 max health. How can I make sure you get at every level even you skipped some of them. Gets + 1 like level 1 = 100 MaxHealth, level 7 = 107, level 200 = 300. Something that checks each time as a level get up.

script is not a local script but still inside the playergui.

I hope my question is understandable.

wait(2)
local player = script.Parent.Parent
local unlock = player.leaderstats.Level
local MH = player.leaderstats.Vis01 -- max health 
local S = player.leaderstats.Vis02 -- max speed
local J = player.leaderstats.Vis03 -- max jumppower
local check = player.leaderstats.Vis04

while true do
    wait(2)
    -- problem --
    if unlock.Value == 2 and check.Value == 1 then
        MH.Value = MH.Value + 1
        check.Value = check.Value + 1
    end
    if unlock.Value == 3 and check.Value == 2 then -- check is only here for preventing loops or when player rejoin they don't get a double maxhealth (check value does save too)
        MH.Value = MH.Value + 1
        check.Value = check.Value + 1
    end
    -- ETC...
    if unlock.Value == 20 and check.Value == 19 then -- works
    S.Value = S.Value + 1
    check.Value = check.Value + 1
    if unlock.Value == 25 and check.Value == 24 then -- works
    J.Value = J.Value + 1
    check.Value = check.Value + 1
end
end
end

Thank you

2 answers

Log in to vote
-1
Answered by
RGRage 45
8 years ago
Edited 8 years ago

I think this is how to fix it, but if I'm wrong someone can do it.

You didn't have to go through all those steps, you just had to set it to where it would add the amount of (levels - 1) to the Max Health Value every time a level was added.

wait(2)
local player = script.Parent.Parent
local unlock = player.leaderstats.Level
local MH = player.leaderstats.Vis01
local S = player.leaderstats.Vis02 -- max speed
local J = player.leaderstats.Vis03 -- max jumppower
local check = player.leaderstats.Vis04

if unlock.Value == 50 and check.Value == 0 then
    S.Value = S.Value + 1
    check.Value = check.Value + 1
end

while true do
    wait(2)
    if unlock.Value > 1 then --Check to see if level is greater than 1
        if MH.Value = MH.Value + (unlock.Value - 2) --Checks for the previous MH Value
            MH.Value = MH.Value + (unlock.Value - 1) --Adds a number equivalent to the amount of levels - 1 so it does not count level 1
        if unlock.Value == 50 and check.Value == 0 then 
        S.Value = S.Value + 1
        check.Value = check.Value + 1
    end
end


0
No, now it goes up every two seconds minetrackmania 186 — 8y
0
Also their were already two errors in your script "if" needs a then and you forgot a end. minetrackmania 186 — 8y
Ad
Log in to vote
-1
Answered by
iDemum 0
8 years ago

This code is super inefficient and super hackable. Recommend you fix it before continuing.

Answer this question