How would I find the order number of a folder within a folder?

I want to find the order number of a folder within a folder, how am I able to do this? Is this possible?

Here is an example:
Screenshot_5

Any replies will be greatly appreciated.

You can loop through it using ipairs and check what its index is. For example:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PetDataFolders = ReplicatedStorage:WaitForChild("PetDataFolders")

for index,Folder in ipairs(PetDataFolders:GetChildren()) do
    print(Folder.Name.." is in position "..index)
end

--[[ Expected Output:

Bear is in position 1
Cat is in position 2
Dog is in position 3
Rabbit is in position 4
Deer is in position 5

--]]

How would I do it if I wanted the script to be inside the pet folder, and to have the index in an IntValue. I’ve changed the locations of the folders but the index comes out as the same for all of them.

When you’re referring to having “the index in an IntValue”, are you wanting to store the Index of each folder into a separate IntValue? Also, since you altered* the locations of the folders, could you show what the updated hierarchy looks like?

Are you planning on adding a different IntValue for each folder? Additionally, will the IntValue be inside of the folder its for or not?

Here is my updated script, it is enabled when the pet folder is replicated into a folder is StarterGui.

for index,Folder in ipairs(script.Parent.Parent:GetChildren()) do

script.Parent.Index.Value = index

end

And I have one IntValue for each pet folder which represents its position within the main folder.

Screenshot_6

I apologize if my script does not make sense as I am fairly new to programming in Lua.

Do you have an individual script for each pet?

Yes, it is enabled once the pet folder is cloned from ReplicatedStorage and put into a new folder in StarterGui where the script put in use.

for index,Folder in ipairs(script.Parent.Parent:GetChildren()) do
         if Folder == script.Parent then --check that it is the folder
                 script.Parent.Index.Value = index --input that value in
         end
end
2 Likes

Thank you so much, works perfectly!

1 Like

Glad to hear :slight_smile: . Have a nice day, good luck!

1 Like