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

How do I make a level up system?

Asked by 3 years ago

I was trying to make a level up system, where if you reach 100 EXP then you get an extra level, but it doesn't work.

Script

if player.leaderstats.Level.EXP.Value >= player.leaderstats.Level.Max then
    player.leaderstats.Level.EXP.Value = 0
    player.leaderstats.Level.Value = player.leaderstats.Level +1
end

Please help.

0
Max is another NumberValue? If yes, then, try to put Max.Value genilsonotavio 132 — 3y
0
Have you checked the path? OfflinePoggers 0 — 3y

2 answers

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

If Level.Max is a NumberValue or another ValueBase you need to check the Value of this Instance. Like that: Level.Max.Value

Try this

if (player.leaderstats.Level.EXP.Value >= player.leaderstats.Level.Max.Value) then
    player.leaderstats.Level.EXP.Value = 0
    player.leaderstats.Level.Value += 1
end

Hope this help, to more questions put bellow on commentaries.

Ad
Log in to vote
0
Answered by
To0_ny 141
3 years ago

ok, so this is not that hard to do. There is something called "Changed" this event happens whenver the number value is changed, you can find the artical here:

https://developer.roblox.com/en-us/api-reference/event/NumberValue/changed

script:

--====================these are just the leveling requirments=============
game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local exp = Instance.new("IntValue", player)
    exp.Name = "Exp"

    local max = Instance.new("IntValue", player)
    max.Name = "Max"
    max.Value = 100

    local level = Instance.new("IntValue", leaderstats)
    level.Name = "Level"
    level.Value = 1
--============================Below is leveling detector=================== 

    exp.Changed:Connect(function(value) -- changed function
        print("expValue Changed") -- prints whenever you get more exp
        if value == max.Value then --if the exp is bigger than the max exp
            exp.Value = 0 -- resetting the exp to 0 after leveled up
            level.Value += 1 -- adding one more level
            max.Value += 50 --every time you level up, you will need 50 more exp to level up again
            print("YAY U LEVELED UP!!")
        end
    end)
end)

Answer this question