DataSave not loading?

Hello!
This is my current data store script and something is wrong with it. I need to have 100 players stored inside it. I used prints and what I noticed is when I leave it saves 100 people, but when I join it only loads 66.
When I first inserted everyone to the table I just put every person in the P2WIDs table. There were only 66 people that I had to put in the table back then. Now there are more than 100 but as I said it only loads the 66 people.

local DataStoreService = game:GetService("DataStoreService")
local P2WDataStore = DataStoreService:GetDataStore("P2W3RD")
local P2WIDs = {}
local checking = false
game.Players.PlayerAdded:Connect(function(player)
	if checking == false then
		checking = true
		local id = P2WDataStore:GetAsync("paytowin")
		if id then
			for i, userId in pairs(id) do
				table.insert(P2WIDs, userId)
                print(userId) --prints out 66 players
			end
		end
	end
end)

local function saveP2WIDs(player)
	local success, errorMessage = pcall(function()
		P2WDataStore:SetAsync("paytowin",P2WIDs)
        local id = P2WDataStore:GetAsync("paytowin")
		if id then
			for i, userId in pairs(id) do
				print(userId) --prints out 100 players
			end
		end
	end)
	if success then
		print("Saved Data")
	else
		print("Error: "..errorMessage)
	end
end

game.Players.PlayerRemoving:Connect(function(player)
	saveP2WIDs(player)
end)

game:BindToClose(function()
	for i, player in pairs(game.Players:GetPlayers()) do
		saveP2WIDs(player)
	end
end)

From the looks of the documentation, the game will only wait 30 seconds for anything in :BindToClose() to run before it shuts down. Are you sure it’s finishing before that?

The game will wait a maximum of 30 seconds for all bound functions to complete running before shutting down. After 30 seconds, the game will shut down regardless if all bound functions have completed or not.

If you run saveP2WIDs while the game is running does it save the data properly?

1 Like

I believe your issue is due to the fact you’re trying to use pcall() when using :SetAsync() instead of using pcall() when using :GetAsync() ← as you should.

1 Like

I made some changes to the script since making the post. And it includes what you said. I’m still having the same problem as before. But I think I’m just gonna switch to Profile Service, it’s way more reliable than normal Data Stores.