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

Help with a level up script please?

Asked by 8 years ago

Hello, Im trying to make a level script. I got the leaderboard but, how must i make that when someone gets killed it gives XP? Code:

function PlayerAdded(Player)
    local stats = Instance.new("IntValue")
    local xp = Instance.new("IntValue")
    local lvl = Instance.new("IntValue")
    lvl.Value = 1
    xp.Value = 0

    xp.Parent = stats
    lvl.Parent = stats
    stats.Parent = Player

    xp.Name = "Xp"
    lvl.Name = "Level"
    stats.Name = "leaderstats"

    if xp.Value == 120 and lvl.Value == 1 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 200 and lvl.Value == 2 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 320 and lvl.Value == 3 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 450 and lvl.Value == 4 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 580 and lvl.Value == 5 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 800 and lvl.Value == 6 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 1200 and lvl.Value == 7 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 1500 and lvl.Value == 8 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 1850 and lvl.Value == 9 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 2005 and lvl.Value == 10 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 2300 and lvl.Value == 11 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 2600 and lvl.Value == 12 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 2950 and lvl.Value == 13 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 3200 and lvl.Value == 14 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 3500 and lvl.Value == 15 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 3855 and lvl.Value == 16 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 4000 and lvl.Value == 17 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 4550 and lvl.Value == 18 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 4900 and lvl.Value == 19 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 5500 and lvl.Value == 20 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    end
    local maxlvl = 20
    if game.Players.LocalPlayer.stats.level > 20 then
    warn(baad)
    end
    if sbb then
        print(good)

elseif not sbb then
    warn(bad)
    end
end
maxlvl = 20
game.Players.PlayerAdded:connect(PlayerAdded)
sbb = game.Players.LocalPlayer:FindFirstChild("stats")
good = "A player joined and loaded succesfully!"
bad = "A player joined and haven't loaded!"
baad = "A player got more than" ..maxlvl.. "levels!"

Yeah, pretty long. I want to compress this too,

if xp.Value == 120 and lvl.Value == 1 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 200 and lvl.Value == 2 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 320 and lvl.Value == 3 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 450 and lvl.Value == 4 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 580 and lvl.Value == 5 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 800 and lvl.Value == 6 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 1200 and lvl.Value == 7 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 1500 and lvl.Value == 8 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 1850 and lvl.Value == 9 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 2005 and lvl.Value == 10 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 2300 and lvl.Value == 11 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 2600 and lvl.Value == 12 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 2950 and lvl.Value == 13 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 3200 and lvl.Value == 14 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 3500 and lvl.Value == 15 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 3855 and lvl.Value == 16 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 4000 and lvl.Value == 17 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 4550 and lvl.Value == 18 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 4900 and lvl.Value == 19 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    elseif xp.Value == 5500 and lvl.Value == 20 then
        xp.Value = 0
        lvl.Value = lvl.Value+1
    end

But i want the max XP to increase each levels... Help please?

0
P.S: I want this script to work in online mode, Im wondering how to make it work in a solo map, but i want this for a RPG map. loulou1112 35 — 8y

2 answers

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

shortened:

local levelup={120,200,320,450,580,800,1200,1500,1850,2005,2300,2600,2950,3200,3500,3855,4000,4550,4900,5500}
game.Players.PlayerAdded:connect(function(Player)
    local stats = Instance.new("IntValue")
    local xp = Instance.new("IntValue",stats)
    xp.Name = "Xp"
    xp.Value = 0
    local lvl = Instance.new("IntValue",stats)
    lvl.Name = "Level"
    lvl.Value = 1
    stats.Parent = Player
    stats.Name = "leaderstats"
    xp.Changed:connect(function()
        if xp.Value>=levelup[lvl.Value]then
            xp.Value=xp.Value-levelup[lvl.Value]
            lvl.Value=lvl.Value+1
        end
    end)
end)

To tell when you kill someone, check if they're dead after you've done damage from the weapon. If they're dead and they weren't dead before then you killed them. Tell the server script that so it can give you xp.

0
I dont understand good.... Im not english btw, Im french. loulou1112 35 — 8y
0
Weapon does damage. If the humanoid it did damage to wasn't dead before and now it is, then the weapon killed it. 1waffle1 2908 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

If you're going to be killing npc's you can have a script that uses the semi-same technique as a linked sword and when the npc's health turns to 0 and it calls the Dead function, you can find the killer and add according XP. You can pracitcally do the same for a regular character, just do game.Players.PlayerAdded and use the Dead function to do above

Answer this question