How to make a gui show players

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).

image

I would like to know how i could make it show the usersnames of the players in the team, like this:

Is any other details are needed, leave a reply and ill try to answer

1 Like

can you show the structure of the ui in explorer

1 Like

I made two different versions, do you want to see both

We cannot make an entire script for you. It’s stated in the pinned post in Scripting support.

Try looking into the Players service and check if there’s anything you can use here.

sure but the latest version of it would be best

structure

lmk if this works

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

1 Like