Help with datastore

Hello, devforum. Its your dumb brain here with a question today!!!
Somebody give me an explanation cuz I not understanding the lines of code that has the comment i put:

Players.PlayerAdded:Connect(function(player)
	Instance.new("Folder",player).Name = "Pets"
	Instance.new("Folder",player).Name = "PetsEquiped"
	local key = player.UserId
	local Pets = player:WaitForChild("Pets")
	local PetsE = player:WaitForChild("PetsEquiped")
	for i,v in pairs(game.ReplicatedStorage:WaitForChild("Pets"):GetChildren()) do
		Instance.new("IntValue",Pets).Name = tostring(v)
	end
	wait(1)
	local savedLevel = data:GetAsync(key)
	if savedLevel ~= nil then
		for i, data in pairs(savedLevel) do
			local pet = Pets:FindFirstChild(data[1])
			local petEq = PetsE:FindFirstChild(data[1])
			if pet and petEq then
				pet.Value = data[2] --the part where im mostly confused
			else
				local instance = Instance.new(data[3]) --the part im confused again
				if instance then
					instance.Name = data[1] --i dont get it
					instance.Value = data[2] --i dont understand
					instance.Parent = Pets
				end
			end
		end
	else
		data:SetAsync(key, {})
	end
end)

Your for loop creates a new local variable which redefines a previous variable named “data”.

It iterates through the retrieved data “saved Level” and then sets values to whatever is stored at a given index.

GetAsync returns a table so you’re simply indexing it. Try printing these out and see what you get.

Also doing Instance.new(obj, parent).Property = value is not recommended, you should be creating, assigning values to properties, and then parenting it.

that’s what you get for using a free model from the library :sweat_smile:

I printed the data variable and this happened:

  15:25:28.803  1  -  Server - SaveTablePets:28
  15:25:28.803  4  -  Server - SaveTablePets:29
  15:25:28.804  IntValue  -  Server - SaveTablePets:30
  15:25:31.815  2  -  Server - SaveTablePets:28
  15:25:31.815  0  -  Server - SaveTablePets:29
  15:25:31.816  IntValue  -  Server - SaveTablePets:30
  15:25:34.831  3  -  Server - SaveTablePets:28
  15:25:34.831  0  -  Server - SaveTablePets:29
  15:25:34.831  IntValue  -  Server - SaveTablePets:30

Extremely more confused :sunglasses: lmao
But, now i know what data[3] is

I’m assuming you’re having trouble understanding this? table[number]

table is a table/array/dictionary. The number inside the brackets is the index, or item number.

For example:

local table = {
    "hi",
    "bye"
}

Since “hi” is the first entry, table[1] would return "hi". It’s the first entry in the table.

yes i know that basic stuff. what im questioning is what type of value is in the entry returning.
i know that the third entry is an IntValue but i do not know what is the first and second entry now after i printed the data table.

Well, the first and second are integers and the third is an IntValue?

you could see the reply i made.

Yes, I saw the reply I don’t understand what you’re asking.

sorry! i made this topic when it was 10 pm, so my brain was not functioning well. What i meant to ask was why the two of this values:

are used in:

I believe that bit is just getting the pets based on the loaded datastore values.