How to save instances with DataStores

local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("MyDataStore")

game.Players.PlayerAdded:Connect(function(player)
	
	local ItemsFolder = Instance.new("Folder")
	ItemsFolder.Name = "ItemsFolder"
	ItemsFolder.Parent = player
	
	local PlayerId = "Player_" .. player.UserId
	local data = nil
	
	local success, errormessage = pcall(function()
		data = MyDataStore:GetAsync(PlayerId)
	end)
	
	if data then
		local NewPet = data:Clone()
		NewPet.Parent = ItemsFolder
	end
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local PlayerId = "Player_" .. player.UserId
	
	if player.ItemsFolder:FindFirstChildWhichIsA("Folder") then
		
		local data = player.ItemsFolder.PetOne

		local success, errormessage = pcall(function()
			MyDataStore:SetAsync(PlayerId, data)
		end)

		if success then
			print("Success")
		elseif errormessage then
			warn(errormessage)
		end
	end
	
end)

game:BindToClose(function()
	wait(1)
end)

So I’ve been looking on YouTube for a video on how to save instances in a DataStore. In my case, the instance would be a pet or item in someone’s backpack which stores information about their pet/item. Unfortunately, I couldn’t find a good video or a clear/common answer from devforum posts either. Is there a simple way to do this?

You cannot save instances inside of a datastore, you’ll have to save their name or a special key and then load in from the name whenever you do that,

Ok. I’ll look into learning how to do this. Thank you

Adding onto what @EnvisionDev said,
A classic way to see that you can ‘save instances’ is - tools.
But what you do there, is you have a folder with tools, and those tools are saveable.

to see more: