How could I give a GUI to a player based on their team?

Hi, pretty much what the title says. I want to have a GUI but only give it to people who spawn onto a certain team (for instance you go on police team it gives you a police gui etc…)

I’m not really sure how to start with this: any help is appreciated :smiley:

Assuming you will be using the team service, you could just use a for loop.

for i, child in pairs(Teams.Police:GetChildren())
   child.PlayerGui.PoliceGui.Visible = true

You can copy and paste the GUI from the server and into the player’s PlayerGui.

local Players = game:GetService("Players")
local TeamColor ="color") -- change this
local Gui = -- change this

local function PlayerAdded(plr)
	local playerGui = plr:WaitForChild("PlayerGui")
	if plr.TeamColor == TeamColor then
		local copy = Gui:Clone()
		copy.Parent = playerGui

for _, plr in ipairs(Players:GetPlayers()) do
	spawn(function() PlayerAdded(plr) end)

This video explains how the PlayerAdded stuff works.

EDIT: Oh actually JigglyWiggles has a better solution using teams. But instead of putting the GUI into the PlayerGui by default and then making it visible, paste it into their PlayerGui.

1 Like