✓ Accepted answer
The GetChildren() method is a table of the children from it's represented container. So if I said model:GetChildren() that would be a table of the children within it.
Generic Loops can, technically, break down the table to elements by using for as it's iterator, and one of it's 'most' commonly used function, pairs(). This receives all the values and combines it into one value.
local children=game.Players:GetPlayers()
function test()
for index, values in pairs(children) do
values.PlayerGui.Test.Frame.Visible=true
else
values.PlayerGui.Test:Destroy()
end
end
game.Players.PlayerAdded:connect(test)
Edited
To make technical search if the player's name 'matches' any of the titles given in the array, we'd use, once again, a generic loop.
local names={"Player","Player1","Player2"}
function namecheck(player,names)
for index, value in pairs(names) do
if player.Name==value then
return true
end
return false
end
function test()
for _, values in pairs(game.Players:GetChildren()) do
if namecheck(values,names) then
values.PlayerGui.Test.Frame.Visible=true
else
values.PlayerGui.Test:Destroy()
end
end
end
1 comment
edited.