Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my level system not want to level up when I reach the needed XP amount?

Okay so I tried making a level system, everything works apart from leveling up, I have tried to give myself "50" XP (That is how much is required to level up) my XP goes to 50 but my level does not seem to want to change to level 2.. I am not getting anything in the output box. Can someone help me please? I have been trying to fix this problem for so long now!

Here is the level up system code!

local DataStore = game:GetService("DataStoreService")
local lvl = DataStore:GetDataStore("LevelSaveSystem")
 
game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Folder",player)
    leaderstats.Name = "leaderstats"
    local Level = Instance.new("IntValue",leaderstats)
    Level.Name = "Level"
    Level.Value = lvl:GetAsync(player.UserId) or 1
    Level.Changed:connect(function()
        lvl:SetAsync(player.UserId, Level.Value)
    end)
   
    if (Level.Value > 100) then -- MaxLevel
        Level.Value = 100
    end
   
    local DataStore = game:GetService("DataStoreService")
    local xp = DataStore:GetDataStore("XPSaveSystem")
   
    local XP = Instance.new("IntValue",leaderstats)
    XP.Name = "XP"
    XP.Value = xp:GetAsync(player.UserId) or 0
    xp:SetAsync(player.UserId, XP.Value)
    XP.Changed:connect(function()
        xp:SetAsync(player.UserId, XP.Value)
    end)
        XP.Changed:connect(function()XPChange(player,XP,Level) end)
       
end)
 
function XPChange(player,XP,Level)
    if XP.Value >= Level.Value*50 then -- Takes 50 XP to get to Level 2 then 100 XP to get to Level 3 etc... also If you level up then...
        XP.Value = 0
        Level.Value = Level.Value+1
    end
end
 
game.Players.PlayerRemoving:connect(function(player)
    lvl:SetAsync(player.UserId, player.leaderstats.Level.Value)
    DataStore:GetDataStore("XPSaveSystem"):SetAsync(player.UserId, player.leaderstats.XP.Value)
   
end)

8 comments

0

omg format your code please

0

I did.

0

You have two functions connected to XP.Changed, try merging them into one. And use Connect (with capital "C"), as connect is deprecated.

0

Yeah I have done that, still does not work, but thank you for the help!

0

Would you like me to answer the script by rewriting it?

0

Try doing a loop not a function

0

Thank you to everyone that has been willing to help me! I have finally fixed the script and it is now working!

0

0_0

1 answer

I'm not sure, but have you tried giving yourself more than 50 XP?

This discussion is preserved as it was. New answers, comments, and votes are closed.