I'm working on a game where the player collects papers, and it has an autobackup in workspace for cloud storage every 30 seconds:
Players = game.Players
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("Papers")
while true do
wait(15)
for _,v in pairs(Players:GetChildren()) do
local character = v.Character
if character then
local player = Players:GetPlayerFromCharacter(character)
print (player)
local papers = player.leaderstats:WaitForChild("Papers Collected").Value
experienceStore:SetAsync(player, papers) --sync papers
end
end
end
The problem is whenever a player joins they, for some reason, get the same number of papers as the last backed up player automatically set, regardless of if they've played before and had a different number. Here's the sync:
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("Papers")
function onPlayerEntered(player)
local success, currentpapers = pcall(function()
return experienceStore:GetAsync(player)
end)
player.leaderstats:WaitForChild("Papers Collected").Value = currentpapers
end
game.Players.PlayerAdded:connect(onPlayerEntered)
That one is in serverscriptservice. Any clue what's going on?

1 comment
Btw, make sure to use the task.wait() function instead, it is much reliable and faster and the old wait function will get deprecated