So, I'm trying to save a Table using DataStore. It's coming up with 2 errors. I'm trying to print every value inside of the table and it's giving me this error
16:26:55.044 - ServerScriptService.Script:16: bad argument #1 to 'pairs' (table expected, got nil)
16:26:55.044 - Stack Begin
16:26:55.044 - Script 'ServerScriptService.Script', Line 16
16:26:55.045 - Stack End
And everytime I exit my test in studio, or in a live server, it gives me this error when I'm trying to save my table.
16:26:56.480 - ServerScriptService.Script:25: attempt to index upvalue 'testList' (a nil value)
This is the ServerScript inside of ServerScriptService
local testList = {33788911}
local testStore = game:GetService("DataStoreService"):GetDataStore("TestStore")
game.Players.PlayerAdded:Connect(function(player)
local success,errorMessage = pcall(function()
newList = testStore:GetAsync("testData-KB")
end)
if success then
testList = newList
print("Test Data Was Loaded!")
else
warn(errorMessage.." | There Was An Error Loading Test Data!")
end
for _,p_ID in pairs(testList) do
if player.UserId == p_ID then
print("Special Player "..player.Name.." Has Arrived!")
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errorMessage = pcall(function()
testList:SetAsync("testData-KB",testList)
end)
if success then
print("Test Data Was Saved!")
else
warn(errorMessage.." | There Was An Error In Saving The Test Data!")
end
end)
I'm not sure if I've formatted something wrong or if I just did this wrong in general.

1 comment
Thanks too! Your's was just a bit more detailed