So. I’m working on this datastore script for my roblox game, and I’m using a table with 3 different values. The odd part is the fact that only 2 of the values are saving (level and cash) but the 3rd one won’t (banned). I have no idea what the problem is as I don’t do much work with datastore.
local datastore = game:GetService("DataStoreService")
local playerdata = datastore:GetDataStore("PlayerData")
local function create_table(player)
local player_stats = {}
for _, stat in pairs(player.stats:GetChildren()) do
player_stats[stat.Name] = stat.Value
end
return player_stats
end
local function onplayerexit(player)
local player_stats = create_table(player)
local sucess, err = pcall(function()
local playerUserId = "player_"..player.UserId
playerdata:SetAsync(playerUserId, player_stats)
end)
if not sucess then
warn("could not save")
end
end
local function onplayeradded(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "stats"
leaderstats.Parent = player
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = player.stats
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = player.stats
local banned = Instance.new("BoolValue")
banned.Name = "banned"
banned.Parent = player.stats
local playerUserId = "player_"..player.UserId
local data = playerdata:GetAsync(playerUserId)
if data then
Cash.Value = data["Cash"]
leaderstats.Level.Value = data["Level"]
else
leaderstats.Cash.Value = 0
leaderstats.Level.Value = 0
end
end
game.Players.PlayerAdded:Connect(onplayeradded)
game.Players.PlayerRemoving:Connect(onplayerexit)
Any help is much appreciated.