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)

2 comments
Theres a way easier way to do this!
what is it, can you help?