Don't close me! Ahh!
I've made a leaderboard script but can't for the life of me figure out how how to do this. I've been trying all day to make the exp reset once it reaches 100 and award 1 level.
Here's the leaderboard script:
local levelstore = game:GetService("DataStoreService"):GetDataStore("Levels")
local expstore = game:GetService("DataStoreService"):GetDataStore("Exp")
function saveInt(player, score, key)
if player.userId > 0 then
expstore:SetAsync(player.userId .. " " .. key, score
)
end
end
function loadInt(player, stat, key)
if player.userId > 0 then
stat.Value = expstore:GetAsync(player.userId .. " " .. key)
end
end
game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local level = Instance.new("IntValue", stats)
level.Name = "Level"
level.Value = 1
local exp = Instance.new("IntValue", stats)
exp.Name = "Exp"
exp.Value = 0
player:WaitForDataReady()
loadInt(player, exp, "Exp")
end)
function playerRemoving(player)
local stats = player:FindFirstChild("leaderstats")
if stats ~= nil then
saveInt(player, stats.Exp.Value, "Exp")
end
end
game.Players.PlayerAdded:connect(function(player)
game.Players.PlayerRemoving:connect(playerRemoving)
end)

4 comments
Hope this helps
Doesn't work, hybrid :C
This won't support instances where the user's experience is more than twice the cap, and the user should be gaining 2 levels instead of 1. This also won't carry over the remaining experience if it's not divisible by the cap.
good 4 u