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