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)