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

How do i make it so when the player levels up, their amount of exp resets?

Asked by 7 years ago
Edited 7 years ago

P1. So i am trying to make a leaderboard leveling system but when i add like 100 exp for it the level up the 100 exp stays, i want to the exp to reset or if they let say gain 10 more than the exp required to level up their exp would be 10 and their level would be the next level

player = game.Players.LocalPlayer 

game.Players.PlayerAdded:connect(function(plr)
    local ldrstats = Instance.new('Folder',plr)
    ldrstats.Name = 'leaderstats'


local lvl = Instance.new('IntValue',ldrstats)
    lvl.Name = 'Level'
    lvl.Value = 0


local xp = Instance.new('IntValue',ldrstats)
    xp.Name = 'Exp'
    xp.Value = 0
local function update()
 lvl.Value = math.floor(xp.Value/100)
end
xp.Changed:connect(update)

if player.leaderstats.Level.Value + 1 then
player.leaderstats. Exp.Value = 0
end
end)

P2. , How do i make it so that you require certain amounts of exp so level up so like at level 1 you need 100 to get to level 2 and u need 200 to get to level 3 (you wont have to answer p2)

1 answer

Log in to vote
0
Answered by
thesit123 509 Moderation Voter
7 years ago
Edited 7 years ago

I think this is what you were kind of looking for...

Just copy and paste in after the third one and change the 1, 200, and 300 to fit your needs

if lvl.Value == 1 then
    if xp.Value > 200 then
        lvl.Value = lvl.Value + 1
        xp.Value = xp.Value - 300
    end
end

In A Script

game.Players.PlayerAdded:connect(function(Plr)-- Player Joined
    Plr.CharacterAdded:connect(function(Char) -- Players' Character Added

        -- Setting Variables
        local ldrstats = Instance.new("Configuration",Plr)
        ldrstats.Name = "Leaderstats"

        local lvl = Instance.new("IntValue", ldrstats)
        lvl.Name = "Level"
        lvl.Value = 0

        local xp = Instance.new("IntValue", ldrstats)
        xp.Name = "Exp"

        xp.Changed:connect(function() -- Exp Value Changed
            -- Player is Level 0
            if lvl.Value == 0 then
                if xp.Value > 100 then
                    lvl.Value = lvl.Value + 1
                    xp.Value = xp.Value - 100
                end
            end
            -- Player is Level 1
            if lvl.Value == 1 then
                if xp.Value > 200 then
                    lvl.Value = lvl.Value + 1
                    xp.Value = xp.Value - 300
                end
            end
            -- Player is Level 2
            if lvl.Value == 2 then
                if xp.Value > 300 then
                    lvl.Value = lvl.Value + 1
                    xp.Value = xp.Value - 300
                end
            end

        end)
    end)
end)

And this is just a random Exp Giver

In A Script

script.Parent.Touched:connect(function(Hit)
    local PlrN = Hit.Parent.Name
    local Plr = game.Players:FindFirstChild(PlrN)
    if Plr then
        local ldrs = Plr:FindFirstChild("Leaderstats")
        if ldrs then
            local exp = ldrs:FindFirstChild("Exp")
            if exp then
                exp.Value = exp.Value + 100
            end
        end
    end
end)
0
leader board doesnt even show up anymore but thanks for the help Ssj4Gokhan10 14 — 7y
0
Instead of Folder for Leaderstats when creating new Instance, Replace it with "Configuration". Hope I was helpful thesit123 509 — 7y
Ad

Answer this question