Hello, fellow developers. Today I set up a cash, level, and exp system, following a HowToRoblox tutorial for the level and exp stats. While playtesting, I found that only the cash leaderstat saves, and not the other ones. I’ve looked through the script and found nothing that could be causing this problem. It isn’t any external scripts either, as the only ones that use them work perfectly fine with the cash as well. Any help?
The tutorial video: How to Make a LEVEL SYSTEM | HowToRoblox
The Leaderstats script (inside ServerScriptService):
local DataStoreService = game:GetService("DataStoreService")
local CashDataStore = DataStoreService:GetDataStore("Cash")
local LevelDataStore = DataStoreService:GetDataStore("Level")
local ExpDataStore = DataStoreService:GetDataStore("Exp")
function incrementExp(player, increment)
for i = player.leaderstats.Exp.Value, player.leaderstats.Exp.Value + increment do
player.leaderstats.Exp.Value = i
wait()
end
end
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder", Player)
Leaderstats.Name = "leaderstats"
local Cash = Instance.new("IntValue", Leaderstats)
Cash.Name = "Cash"
Cash.Value = 0
local Level = Instance.new("IntValue", Leaderstats)
Level.Name = "Level"
Level.Value = 1
local Exp = Instance.new("IntValue", Leaderstats)
Exp.Name = "Exp"
Exp.Value = 0
local CashData = CashDataStore:GetAsync(Player.UserId)
if CashData then
Cash.Value = CashData.Cash
end
local LevelData = LevelDataStore:GetAsync(Player.UserId)
if LevelData then
Level.Value = LevelData.Cash
end
local ExpData = ExpDataStore:GetAsync(Player.UserId)
if ExpData then
Exp.Value = ExpData.Cash
end
Exp:GetPropertyChangedSignal("Value"):Connect(function()
local neededExp = math.floor(Level.Value ^ 1.5 + 0.5) * 500
if Exp.Value >= neededExp then
Level.Value += 1
end
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
CashDataStore:SetAsync(Player.UserId, {
["Cash"] = Player.leaderstats.Cash.Value;
})
LevelDataStore:SetAsync(Player.UserId, {
["Level"] = Player.leaderstats.Level.Value;
})
ExpDataStore:SetAsync(Player.UserId, {
["Exp"] = Player.leaderstats.Exp.Value;
})
end)
Thanks,
SpeakerDev