Saving Tables in DataStore error

Hello. I am running across an issue where whenever I try and save a table with data inside it, it gives this.
image
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?

Any help will be very much appreciated!

Any help would be very much appreciated!

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.

What are you trying to say? That the key is an actual player? Cause I can assure you, it’s not.

Hi!

This is the array that it tries to store.
image

Yes, I see, but whenever I try and put the things inside a table, it just returns that it can’t save dictionaries.

It’s been a long time since I’ve worked with normal DataStore.

Does this have the same issue?

petstore = DataStore:SetAsync(player.UserId.."_pets",{pets})

No, it seems that it still returns the same error.

So it’s a yes, the issue persists?

Yes, it does. I said it still returns the same error.

Just making sure, because I asked if the code I sent had the same issue and you replied with no. Give me a minute. :slight_smile:

Please show me what “GetPets” does, because it might be returning valueobjects and not the values themself.

This is all GetPets is

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

image
and that is what the Table (Pets) holds.

And what is “Pets” in GetPets?

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

No I don’t see Pets defined anywhere.
image

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.
image

It’s quite relevant. If Pets for example was a folder, containing all pets, and you returned a objectvalue, then this would be the problem.

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.

2 Likes

Owner, seems to be a object and not a name?