There is no point in doing that, just use ipairs loop. If friend suggested you a challenge then fine, you can use normal for loop like this:
local Players = game:GetService("Players")
local function get_characters()
local clients = Players:GetPlayers()
local characters = {}
for index = 1, #clients do
local client = clients[index]
if client then
table.insert(characters, client.Character)
end
end
return characters
end
If that is also restricted to you, use the deprecated foreach / foreachi (Difference between them is same as between pairs and ipairs, the one with "i" goes by order and breaks the loop if hits a nil value) loop which runs function for each element in a table:
local Players = game:GetService("Players")
local function get_characters()
local clients = Players:GetPlayers()
local characters = {}
local function _add_character(index, client)
if client then
table.insert(characters, client.Character)
end
end
table.foreachi(clients, _add_character)
return characters
end