Hello. I am running across an issue where whenever I try and save a table with data inside it, it gives this.
This is the script when you leave:
local pets = GetPets(player)
local petstore
local succ, err = pcall(function()
print(pets)
petstore = DataStore:SetAsync(player.UserId.."_pets",pets)
end)
print(petstore)
if succ then
print("Successfully saved "..player.Name.." -pet data")
else
warn("There was an error while saving Pet data", err)
end
the GetPets will return the pets inside the Pets Table, which is shown above, I only had 1 pet so it showed 1 pet inside there. But besides that, why is it doing this?
Does the value for owner store the actual player or the player’s name? I’m thinking you’re getting this error because you’re attempting to store an actual player for the owner key.
function GetPets(player, plr)
if plr then
for i, v in ipairs(Pets) do
if v.user == plr.Name then
return v.pets
end
end
end
for i, v in ipairs(Pets) do
if v.user == player.Name then
return v.pets
end
end
end
What do you mean? I just edited my message, below it I showed the contents of the Table Pets under the code. Maybe that’ll answer your question? Pets.pets stores all the pets, then it just returns the table Pets.pets
Pets is located at the top of the script, in like line 5. It stores every player, and everyones pets in a table. That isn’t really relevant, but I showed what the table contains. As lets say they have 3 pets, GetPets will return their pets for the player defined.
Judging on the error you’re receiving, you’re trying to store an instance/object that isn’t supported for DataStore saving. So, the table you’re trying to save most likely has an object stored as a value. Make sure that all of the keys in that table are storing strings/numbers (e.g. the name of the objects/players), and not just actual objects.
That’s the only problem I think that the error is being caused.