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
omg format your code please
I did.
You have two functions connected to XP.Changed, try merging them into one. And use Connect (with capital "C"), as connect is deprecated.
Yeah I have done that, still does not work, but thank you for the help!
Would you like me to answer the script by rewriting it?
Try doing a loop not a function
Thank you to everyone that has been willing to help me! I have finally fixed the script and it is now working!
0_0