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
end

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

local Players = game:GetService("Players")
local TeamColor = BrickColor.new("color") -- change this
local Gui = path.to.gui -- change this

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

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

This video explains how the PlayerAdded stuff works. https://www.youtube.com/watch?v=bX8MxozRTGo

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