Hello, the code below runs through the children in Guis which is a frame that contains multiple imagebuttons. It then prints them, what I’m expecting to come out of it is the name of child. However I’m getting a number as if it was a table or something. Am I doing something wrong?
local Guis = script.Parent.RecGUI:GetChildren()
for i, v in pairs(Guis) do
wait()
print(i)
end
Inside of the loop, you’ll have references to two separate things – in this case, the “i” will refer to the index/“position” in the loop, while “v” will refer to the value associated with the given index, which are the objects inside of the Instance that is being looped through.
In order to retrieve the names of the Instances, you can adjust print(i) to print(v.Name)
Example:
local Guis = script.Parent.RecGUI:GetChildren()
for index, value in pairs(Guis) do
print(value.Name.." is in position "..index.." of the loop.")
--[[ Expected Output:
Dagger is in position 1 of the loop
Flail is in position 2 of the loop
Hammer is in position 3 of the loop
Spear is in position 4 of the loop
--]]
end