I have a save load script it runs fine but doesn’t throw any errors whatsoever, it even says it’s successfully saving and loading when the function run’s. I’m pretty certain the error is not in the script but maybe something else. I’m not entirely sure what the issue is because I’m still learning datastores.
Here is the script
local players = game:GetService("Players")
local DataStore = game:GetService("DataStoreService")
local GameData = DataStore:GetDataStore("GameData")
players.PlayerAdded:Connect(function(player)
local Int = Instance.new("IntValue",player) Int.Name = ("leaderstats")
local kos = Instance.new("NumberValue",Int) kos.Name = ("KOs")
local points = Instance.new("NumberValue",Int)
points.Name = "Points"
local vc = Instance.new("NumberValue",Int) vc.Name = ("VirtualCurrency")
local lvl = Instance.new("NumberValue",Int) lvl.Name = ("lvl")
local xp = Instance.new("NumberValue",lvl) xp.Name = ("XP")
local Swords = Instance.new("Folder",player) Swords.Name = "Swords"
wait(1)
local success, err = pcall(function()
local stuff = GameData:GetAsync(player.UserId.."-StatsData")
for a, b in ipairs(stuff) do
for c, d in ipairs(player.leaderstats:GetDescendants()) do
if d.Name == a then
d.Value = b
end
end
end
end)
if success then
print("loaded data for "..player.Name)
else
print("loading data for "..player.Name.." failed.",err)
end
end)
local function Save(player)
local ls = player.leaderstats
local DataTable = {}
for a, b in ipairs(player.leaderstats:GetDescendants()) do
DataTable[b.Name] = b.Value
end
local success, err = pcall(function()
GameData:SetAsync(player.UserId.."-StatsData", DataTable)
end)
if success then
print("saved data for "..player.Name)
else
print("saving data for "..player.Name.." failed.",err)
end
end
players.PlayerRemoving:Connect(function(player)
Save(player)
end)
game:BindToClose(function()
for i,player in pairs(game.Players:GetChildren()) do
pcall(Save,player)
end
end)