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

I Can't Get My level Up System To Work?

Asked by 5 years ago

So this script is suppose to level you up, but when your xp reaches 700 (when your level should increase) your level does not go up to level 2

local level = game:GetService("DataStoreService"):GetDataStore("Levels")
local xp = game:GetService("DataStoreService"):GetDataStore("XP")
local axp = game:GetService("DataStoreService"):GetDataStore("AXP") --Stands for ammount of xp needed to level up!

function savedata(dataname, playerid, value)
    game:GetService("DataStoreService"):GetDataStore(dataname):SetAsync(playerid, value)
end

game.Players.PlayerAdded:Connect(function(player)
    local leader = Instance.new("Folder")
    leader.Name = "leaderstats"
    leader.Parent = player
    local levelz = Instance.new("IntValue")
    levelz.Value = level:GetAsync(tostring(player.userId)) or 1
    levelz.Name = "level"
    levelz.Parent = player:WaitForChild("leaderstats")
    local xpz = Instance.new("NumberValue")
    xpz.Value = xp:GetAsync(tostring(player.userId))
    xpz.Name = "XP"
    xpz.Parent = player
    local xpn = Instance.new("IntValue")
    xpn.Value = axp:GetAsync(tostring(player.UserId)) or 700
    xpn.Name = "XpNeeded"
    xpn.Parent = player

    xpz.Changed:Connect(function()
        if player:WaitForChild("XP").Value >= player:WaitForChild("XpNeeded").Value then
            levelz.Value = levelz.Value+1
            player:WaitForChild("XP").Value = 0
            xpn.Value = xpn.Value+700
            savedata("levels",player.userId,levelz.Value)
            savedata("XP",player.userId,xpz.Value)
            savedata("AXP",player.userId,xpn.Value)
        else
            savedata("levels",player.userId,levelz.Value)
            savedata("XP",player.userId,xpz.Value)
            savedata("AXP",player.userId,xpn.Value)
        end
        savedata("levels",player.userId,levelz.Value)
        savedata("XP",player.userId,xpz.Value)
        savedata("AXP",player.userId,xpn.Value)
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    savedata("levels",player.userId,player.leaderstats.Level.Value)
    savedata("XP",player.userId,player.XP.Value)
    savedata("AXP",player.userId,player.XpNeeded.Value)
end)
0
Theres a way easier way to do this! Sp1r1tD3v -4 — 5y
0
what is it, can you help? User#28169 0 — 5y

Answer this question