:GetChildren() numbers

How do i select a children depending his number? like, 1 Player1 2 Player2 3 Player3 and i want to select Player3.

Instance:GetChildren()[Number]

2 Likes

Worth noting that GetChildren() might not always return the same ordering of items. So if you want consistent ordering, you need to sort the table given back from GetChildren before accessing the items.

For instance, if you actually have people named Player1, Player2, etc., and want them to be ordered accordingly, you could sort alphabetically:

local children = instance:GetChildren()
table.sort(children, function(child1, child2)
   return child1.Name < child2.Name
end)
local thirdChild = children[3]
3 Likes

If it’s player instances you’re fetching then:

local players = game:GetService("Players")
local playerList = players:GetPlayers()[3]