DataStore Issue

I made the pet system and having an issue with datastore for it, so there the issue how I can save the player’s pets? For ex:

When player got the pet it’s are stringValue and in the pet are level,exp,maxLevel,folder named ‘Boosts’ and in boosts also values, so how I can save values and the pet stringValue without plr.Anything:Clone()?

1 Like

Also if it’s possible make pets saving without table.insert()

That’s how the pet looks if player has it:

1 Like

Why not use tables instead of storing it in folders?

try doing something like this:

local globalPetTable = {}
globalPetTable[plr.Name] = {}
globalPetTable[plr.Name][petId] = "PetName"

Pet ID can be generated using HttpService:GenerateGUID()

The table can be saved into datastore using HttpService:JSONEncode()

1 Like

So it can save all values from Basic/etc folders and put them where they was before?

Instead of making folders, make a table with all these information. It will make it easier to save it to DataStore

The thing is I wanna use folders of the rarity instead tables, or :Clone() since the pet hatching system based of rarirty and makes instance not :Clone().

Since I already checked all youtube tutorials and everyone using just :Clone() or plr.ServerStorage:FindFirstChild(‘petName’) and makes bool/stringValues in just a folder without any rarity, which is not my issue…

If you want to use folders you would have to convert the contents of the folder into a table and save it to the datastore as you cannot store instances as it is in datastores

Can you do the example how it should look? Since I’ve never worked with that issue before.

As @TheBrainy06 has said you cannot store instances as it is in a datastore here is a great alternative,

local datastoreservice = game:GetService("DatastoreService")
local Petstore = datastoreservice:GetDataStore("pets")



local PetFolder ="Folder",plr)
PetFolder.Name = "PetFolder"

local UnCommonPets ="Folder",PetFolder)
UnCommonPets.Name = "Uncommon"

local EpicPets ="Folder",PetFolder)
EpicPets.Name = "Epic"

local CommonPets ="Folder",PetFolder)
CommonPets.Name = "Common"

local RarePets ="Folder",PetFolder)
RarePets.Name = "Rare"

local LegendaryPets ="Folder",PetFolder)
LegendaryPets.Name = "Legendary"



It should be like: ?
for i, v in pairs(plr.Pets:GetChildren()) do
for o, q in pairs(v:GetChildren()) do
if q ~= nil and q:IsA(“StringValue”) then

1 Like

so lets say you have a folder of pets that the player owns you can do something like this

local playerPets = {}
local petsFolder = plr.Pets

for i,v in pairs(petsFolder:GetChildren()) do
	playerPets[v.Name] = {}
	for a,b in pairs(v:GetChildren()) do

I’m already using that but the issue I don’t know how to save in these rarityFolders pet values, which is the my issue and I don’t have any idea how to make it save.

then you should probably read more about DataStores to get a better understanding on how to save/load data

I just never had any exprience saving data with folders like pet rarity, that’s how it should be look if a player has pet:

else: rarity folders are empty

ok so if you already have a table of data then do this

local HttpService = game:GetService("HttpService")

local dataToSave = HttpService:JSONEncode(tableOfData) -- save the string which is returned by this

Prints ‘null’
The code I did:

add this at the end of the function

return playerPets

and change

local dataToSave = HttpService:JSONEncode(tableOfData)


local dataToSave = HttpService:JSONEncode(tableOfData())

Now it doesn’t work, no print

Hi, If you are still experiencing issues I suggest trying this,

Replace this with the ending of your script / when the player leaves the game.

local datatsave = GetService("HttpService"):JSONEncode(tableofdata())
local success,response = pcall(function()
return datasave

if success then
print("Succesfully returned the players pets.")
print("oops, looks like there was an error within saving your data, let me get the response: " .. response