im trying to make it so when u have 1000 xp you hit level 1 but when u get 2257 you get to level 2 idk how id script that in my current leaderboard script anyone know to how with my script? CURRENT SCRIPT NEED FIXING
local level = game:GetService("DataStoreService"):GetDataStore("Levels") local Xp = game:GetService("DataStoreService"):GetDataStore("Xp") local axp = game:GetService("DataStoreService"):GetDataStore("AXP") local RequiredXP = { [0] = 1000, [1] = 2257 } function savedata(dataname, playerid) 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 levels = Instance.new("IntValue") levels.Value = level:GetAsync(tostring(player.userId)) or 1 levels.Name = "Level" levels.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 1000 xpn.Name = "XpNeeded" xpn.Parent = player Xpz.Changed:connect(function() if player:WaitForChild("Xp").Value >= player:WaitForChild("XpNeeded").Value then levels.Value = levels.Value+1 xpn.Value = RequiredXP[levels.Value] savedata("levels",player.userId.levels.Value) savedata("Xp",player.userId.Axp.Value) savedata("Axp",player.userId.xpn.Value) else savedata("levels",player.userId.levels.Value) savedata("Xp",player.userId.Axp.Value) savedata("Axp",player.userId.xpn.Value) end end) end)
At Line 30, you can switch that to index a table of XP needed for each level. In order to do this, add a table at the beginning of the script that's something like,
local RequiredXP = { [0] = 1000, -- [current level] = amount required to level up [1] = 2257 -- You can easily add more for each level, but be aware that there will be a max level if you do it this way }
You can index it by doing RequiredXP[levels.Value] and it will spit out whatever it equals.
( xpn.Value = RequiredXP[levels.Value] )
This allows for easy customization. As long as you know what you're doing, you'll be able to figure this out.
Or you can have it at a fixed rate where you just multiply it to get it at 2257. After that, you'll have to deal with some issues of where it might take too long to level up. If you're wondering what that rate is, it is 2.257.