I've been trying to get one data store to save multiple values by using a table, but it's not working. Every time I leave and rejoin, none of the values load back. I have no idea what i'm doing wrong so I really need help solving this bug.
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = "Cash"
Cash.Value = 0
local XP = Instance.new("IntValue",leader)
XP.Name = "XP"
XP.Value = 0
local Lvl = Instance.new("IntValue",leader)
Lvl.Name = "Lvl"
Lvl.Value = 1
local EquippedKnife = Instance.new("StringValue", player)
EquippedKnife.Name = "EquippedKnife"
EquippedKnife.Value = "Default"
local EquippedGun = Instance.new("StringValue", player)
EquippedGun.Name = "EquippedGun"
EquippedGun.Value = "Default"
local playerData = ds:GetAsync(tostring(player.UserId))
if playerData ~= nil then
Cash.Value = playerData[1]
XP.Value = playerData[2]
Lvl.Value = playerData[3]
EquippedKnife.Value = playerData[4]
EquippedGun.Value = playerData[5]
end
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(tostring(player.UserId),
{
player.leaderstats.Cash.Value,
player.leaderstats.XP.Value,
player.leaderstats.Lvl.Value,
player.EquippedKnife.Value,
player.EquippedGun.Value
})
end)

2 comments
Are you testing in studio? If so, try testing in game
I've tried both in-studio and in-game