What do you want to achieve?
I want my for i, v in pairs to return the only items in the list
What is the issue?
I want to know why my for i, v in pairs loop returns multiples of my pets
What solutions have you tried so far?
Unsure why its happening in the first place so I’m unsure how to search exactly or word it.
===================One Loop Method===========================
for i = 1, #PetInventory do
local pet = PetInventory[i]
print(i, PetInventory[i].Name, PetInventory[i].Value)
==========The other=====================
for i , v in pairs(PetInventory:GetChildren()) do
print(i, v)
Just print the number of children in pet inventory for me. → print(#PetInventory) it should print as 4, if they are only 4 pets in the inventory. And if not, then we can narrow down the issue as it would seem the pets are getting duplicated.
Also can you include what you have “PetInventory” set to (What the variable is)
I suppose it must be going on somewhere, I’ll search my game with ctrl,shift, f and find for loops that have to do with my pets.
This print runs at the start of the game, I’m trying to cross reference a pet ID and the slot the pet is sitting in for a sell function so it’s only firing once.
Hmm, I mean it isn’t that script. (At least I don’t think) So I think you have ran the code multiple times within another script.
local function CreateFakeFolder(Player)
local PetInventory = Instance.new("Folder", Player)
PetInventory.Name = "PetInventory"
local Bee = Instance.new("BoolValue", PetInventory)
Bee.Name = "Bee"
local Bunny = Instance.new("BoolValue", PetInventory)
Bunny.Name = "Bunny"
local Bunny = Instance.new("BoolValue", PetInventory)
Bunny.Name = "Bunny"
local Cat = Instance.new("BoolValue", PetInventory)
Cat.Name = "Cat"
end
local function SortPetInventory(Player)
local PetInventory = Player:WaitForChild("PetInventory")
for i , v in pairs(PetInventory:GetChildren()) do
print(v)
end
end
game.Players.PlayerAdded:Connect(function(Player)
CreateFakeFolder(Player)
wait()
SortPetInventory(Player)
end)
I just ran that in studio, to create a replica of your folder and it works fine.