I have a script that saves data of a folder full of intvalues, when i enter the game and the values change, i leave and rejoin and no data have been saved to how i had it before i left. is it a script problem or a ingame problem? help
script:
there are not any errors in the output
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("SaveData6")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local nametagPurchases = ReplicatedStorage:WaitForChild("NametagPurchases")
local firstPage = nametagPurchases.FirstPage
local function SavePlayerData(player)
local success,errormsg = pcall(function()
local SaveData = {}
for i,stats in pairs(firstPage:GetChildren()) do
if stats:IsA("IntValue") then
SaveData[stats.Name] = stats.Value
end
end
print("saving player data...")
SaveDataStore:SetAsync(player.UserId,SaveData)
end)
if not success then
return errormsg
end
end
Players.PlayerAdded:Connect(function(player)
local Stats = Instance.new("Folder")
Stats.Name = "leaderstats"
Stats.Parent = player
local points = Instance.new("IntValue",Stats)
points.Name = "Points"
local Data = SaveDataStore:GetAsync(player.UserId)
if Data then
for i,stats in pairs(firstPage:GetChildren()) do
if stats:IsA("IntValue") then
stats.Value = Data[stats.Name]
end
end
else
print(player.Name .. " has no data.")
end
end)
Players.PlayerRemoving:Connect(function(player)
local errormsg = SavePlayerData(player)
if errormsg then
warn(errormsg)
end
end)
game:BindToClose(function()
for i,player in pairs(Players:GetPlayers()) do
local errormsg = SavePlayerData(player)
if errormsg then
warn(errormsg)
end
end
wait(2)
end)

1 comment
It seems to save the data correctly. Might be a problem with loading the data. Another thing is that is firstPage is a global variable so it will change the same thing for every player.
Also, try to test it not in studio. Datastores may not work in studio.