So, I’ve been working on something, but when i try to use it i get the error this error:
“error generating data: ServerScriptService.Serializer:57: invalid argument #1 to ‘pairs’ (table expected, got nil) for slot Slot1 for plr GalacticLemon_Aj”
Here is the code:
local data
local s,x = pcall(function()
print('pcall')
print(workspace:WaitForChild('Blocks'):WaitForChild(plr.Name))
local stuff = {}
local thing = workspace.Blocks:FindFirstChild(plr.Name)
if thing then
for _, t in pairs(workspace:WaitForChild('Blocks'):WaitForChild(plr.Name):GetChildren()) do
print(t.Name)
table.insert(stuff,t)
end
end
--local stuff = workspace.Blocks[plr.Name]:GetChildren()
data = Save.Encrypt(stuff)
I really can’t find any awnsers to this, as most others are un-related
local data
local data
local s,x = pcall(function()
print('pcall')
print(workspace:WaitForChild('Blocks'):WaitForChild(plr.Name))
local stuff = {}
for _, t in pairs(workspace:WaitForChild('Blocks'):WaitForChild(plr.Name)) do
table.insert(stuff,t)
end
--local stuff = workspace.Blocks[plr.Name]:GetChildren()
data = Save.Encrypt(stuff)
end)
Maybe you could try setting it as a variable first and if it is nil, skip adding it?
For example:
local thing = workspace.Blocks:FindFirstChild(plr.Name)
local stuff = {}
if thing then
for _, t in pairs(workspace:WaitForChild('Blocks'):WaitForChild(plr.Name)) do
table.insert(stuff,t)
end
This code is ran when the saveEvent is fired, which I know works well, because I have a print statement in there. I changed the code to look like this which still gives the same error. Also, when I print the names of what’s getting detected, it shows everything.
local data
local s,x = pcall(function()
print('pcall')
print(workspace:WaitForChild('Blocks'):WaitForChild(plr.Name))
local stuff = {}
local thing = workspace.Blocks:FindFirstChild(plr.Name)
if thing then
for _, t in pairs(workspace:WaitForChild('Blocks'):WaitForChild(plr.Name):GetChildren()) do
print(t.Name)
table.insert(stuff,t)
end
end
--local stuff = workspace.Blocks[plr.Name]:GetChildren()
data = Save.Encrypt(stuff)
end)
local su,xa = pcall(function()
local key = tostring(plr.UserId..'&'..(slot))
DS:SetAsync(key,data)
end)
And the error is:
“error generating data: ServerScriptService.Serializer:57: invalid argument #1 to ‘pairs’ (table expected, got nil) for slot Slot1 for plr GalacticLemon_Aj”
I know its not the module, because I have made some other things with the same module that work perfectly.
The pairs loop visible in your provided code looks fine, :GetChildren() never returns nil, only ever an empty array. If workspace.Blocks[plr.Name] didn’t exist, then you’d get an error about that instead. The problem probably lies within the Save.Encrypt(stuff) function on this line:
So we know it isn’t the player name or the table itself, then perhaps there is nothing in the there to retrieve which would also result in a nil value?
Maybe try:
local thing = workspace.Blocks:FindFirstChild(plr.Name)
if thing then
local thingtable = thing:GetChildren()
if thingtable then
data = Save.Encrypt(thingtable)
end
end
end)
local su,xa = pcall(function()
local key = tostring(plr.UserId..'&'..(slot))
DS:SetAsync(key,data)
end)
^
Also, give specific errors (just copy the error and paste it here) and show any other errors if you have them. If you already replied with those, edit your original message and put the full error there so the future helpers can see it.