How can I make a gui that only shows for a certain team

I would like to know how to make a GUI only show for a certain team

2 Likes

Make a function that shows a GUI for a player.
Then when a player is added to the team, use the function on that player.

i dont understant :thinking: :face_with_raised_eyebrow:

In simple words,
Make a function that would make a GUI visible for a player(i.e

local function ShowForPlayer(p)
      local Player = p
      local PlayerGui = p.PlayerGui or p:WaitForChild("PlayerGui")
      -- For this, you can have a GUI that's not already in their PlayerGui, or there is one.
      -- Let's say a GUI is already in their PlayerGui.
      PlayerGui.TeamThing.Visible = true
      -- Let's say there isn't one.
      local TeamThing = (PATH).Gui:Clone()
      TeamThing.Parent = PlayerGui
      TeamThing.Visible = true
end
2 Likes

If you’re still struggling with the issue, I can give you an explanation (Some of these can be difficult to learn after all)

So, there are multiple ways of actually doing this but how about we just do this through a loop for all the players? :thinking:

In the end, we should get something like this:

local Teams = game:GetService("Teams")
local BlueTeam = Teams.BlueTeam
local RedTeam = Teams.RedTeam

for _, Player in pairs(game.Players:GetPlayers()) do
    if Player.TeamColor == RedTeam.TeamColor then
        Player.RedGui.Enabled = true
    elseif Player.TeamColor == BlueTeam.TeamColor then
        Player.BlueGui.Enabled = true
    end
end

Now, you may be asking “How did we manage to get this far?” I’ll try and briefly explain what each thing can do here:

local Teams = game:GetService("Teams")
local BlueTeam = Teams.BlueTeam
local RedTeam = Teams.RedTeam

For this, we’re getting the Teams service so that we can easily access it & we’re also defining what our Teams are gonna be (Red/Blue for now)

Now, the next code is getting all of the players inside the game with the for Index, Value in pairs() do loop

Basically:

for _, Player in pairs(game.Players:GetPlayers()) do
    print(Player)
end

Will basically print out all the possible players in the server like so:

Expected Output:
Jackscarlett
Obj_ective
JadtrugamingYT1
lluckvy

So, now that we got our players here…We can do a if statement check to see if the Player’s TeamColor is equal to the Red/Blue’s TeamColor and if it is, then we can enable our GUI’s to specific players!

  • 1 thing to note, is that all Players have a TeamColor property which is a BrickColor value

  • When showing GUI’s to different players, there are a couple of ways to make it non-visible to the player but for me I just do Gui.Enabled = true (Since Enabled is a BoolValue)

    if Player.TeamColor == RedTeam.TeamColor then
        Player.RedGui.Enabled = true
    elseif Player.TeamColor == BlueTeam.TeamColor then
        Player.BlueGui.Enabled = true
    end

This will check every Player's TeamColor, then assign the GUI’s to each player

It’s a lot to keep in mind, but eventually it can get easier as you go along! :sweat_smile:

1 Like

Basically what @Obj_ective said will work but you would also then need to detect that if a user in that team that the function will run because at the moment it is just a function. What @JackscarIitt should work as well.

if Player.TeamColor == BlueTeam.TeamColor then
    Player.TeamGui.Enabled = true
5 Likes

where should I put this and what type of script

It should be a local script in serverscriptserivce

Make a localscript and put it in StarterPlayerScripts or PlayerGui.

Dont put a LocalScript in ServerScriptService since it won’t run there. ServerScriptService is for Modules and Normal Scripts, not LocalScripts. LocalScripts are only for Client-Sided Scripts.

3 Likes

Ohhhh okay thank you for correcting me