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

Why does my Level up system not level up the player when the xp is higher than the xp needed?

Asked by 4 years ago
Edited 4 years ago

So i have made this script which is a Level up system integrated with the datastore system, now the datastore works well but the Level up part Line 26 - 32 does not. What is the issue? and how do i fix it?

the code:

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("Level")
local ds2 = DataStore:GetDataStore("XP")
local ds3 = DataStore:GetDataStore("XPN")
local success, err = pcall(function()

game.Players.PlayerAdded:connect(function(player)
    local leader = Instance.new("Folder", player)
    leader.Name = "leaderstats"
    ------------------------------------------
    local level = Instance.new("IntValue", leader)
    level.Name = "Level"
    level.Value = ds1:GetAsync(player.UserId) or 1
    ds1:SetAsync(player.UserId.."-Level", level.Value)
    ------------------------------------------
    local xp = Instance.new("NumberValue", player)
    xp.Name = "XP"
    xp.Value = ds2:GetAsync(player.UserId) or 1
    ds2:SetAsync(player.UserId.."-XP", xp.Value)
    ------------------------------------------
    local XPN = Instance.new("IntValue", player)
    XPN.Name = "XPNeeded"
    XPN.Value = ds3:GetAsync(player.UserId) or 1000
    ds2:SetAsync(player.UserId.."-XPNeeded", XPN.Value)

        xp.Changed:connect(function()
        print("+XP SAVING")
        if player:WaitForChild("XP").Value >= player:WaitForChild("XpNeeded").Value then
            level.Value = level.Value+1
            XPN.Value = XPN.Value + 500
            XPN.Value = XPN.Value
            xp.Value = 0
        ds1:SetAsync(player.UserId.."-Level", level.Value)
        ds2:SetAsync(player.UserId.."-XP", xp.Value)
        ds3:SetAsync(player.UserId.."-XPNeeded", XPN.Value)
            else
            ds1:SetAsync(player.UserId.."-Level", level.Value)
            ds2:SetAsync(player.UserId.."-XP", xp.Value)
            ds3:SetAsync(player.UserId.."-XPNeeded", XPN.Value)
        end


game.Players.PlayerRemoving:connect(function(player)

    local SavedData = Instance.new("BindableEvent")
    ds1:setAsync(player.UserId, player.leaderstats.Level.Value)--Level
    ds2:setAsync(player.UserId, player.xp.Value)--XP
    ds2:setAsync(player.UserId, player.XPNeeded.Value)--XPNeeded
    print("SavingData")

    SavedData:Fire()

game:BindToClose(function()
    SavedData.Event:Wait()
end)
end)
end)
end)
end)    
0
What is the output? LUCATIVIOMAD2 54 — 4y
0
Output is clear DaggerSaber 14 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I guess i solved it guys i had to edit the level up part to this :

xp.Changed:connect(function()
        print("+XP SAVING")
        if xp.Value >= XPN.Value then   
        player.leaderstats.Level.Value = player.leaderstats.Level.Value + 1
            XPN.Value = XPN.Value + 500
            XPN.Value = XPN.Value
            xp.Value = 0
        ds1:SetAsync(player.UserId.."-Level", level.Value)
        ds2:SetAsync(player.UserId.."-XP", xp.Value)
        ds3:SetAsync(player.UserId.."-XPNeeded", XPN.Value)
            else
            ds1:SetAsync(player.UserId.."-Level", level.Value)
            ds2:SetAsync(player.UserId.."-XP", xp.Value)
            ds3:SetAsync(player.UserId.."-XPNeeded", XPN.Value)
        end
0
I solved the issue but now the problem is that the XP and XPNeeded dont save :( DaggerSaber 14 — 4y
Ad

Answer this question