In my game, the is a script that assigns you to a random team, then it shows on a gui, like this one (THe Player 1’s and Player 2’s is just an example).
I would like to know how i could make it show the usersnames of the players in the team, like this:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local UI = Player.PlayerGui.Teams2.Frame
local GetEmptyFrame = function(Team)
for i,v in pairs(UI[Team]:GetChildren()) do
if (string.find(v.Name, "P")) and (v.Visible == false) then --// check if the textlabel is not the title on top and if its not already set as another player
return v
end
end
end
local ClearFrames = function()
for i,v in pairs(UI.blueFrame:GetChildren()) do
v.Visible = false
end
for i,v in pairs(UI.redFrame:GetChildren()) do
v.Visible = false
end
end
local UpdateUi = function()
ClearFrames()
for i,v in pairs(game:GetService("Players"):GetChildren()) do
if (v.Team ~= nil) then
local FrameName = ""
if (v.Team.Name == "Red") then
FrameName = "redFrame"
elseif (v.Team.Name == "Blue") then
FrameName = "blueFrame"
end
local Frame = GetEmptyFrame(FrameName)
if (Frame ~= nil) then
Frame.Text = v.Name
Frame.Visible = true
end
end
end
end