Remove Specific GUI on a specific team

While on a specific team, for this instance let’s say the Team Color is Black.

I want a StarterGUI called MorphSelection to not appear. That GUI and that GUI only. I’ve tried to script this myself, however, I cannot seem to do it. So I figured someone here may be able to assist me in this task.

Sorry for the terrible description. I was never a creative writer.

local teamBlack = -- get team black
local gui = -- get gui

game.Players.PlayerAdded:Connect(function(plr)
     if plr.TeamColor == teamBlack.TeamColor then
         gui.Enabled = false
     end
end)

That should work I did not test it though. Just store the team in variable teamBlack and the gui in variable gui.

1 Like

Do I just copy paste exactly that into a Script and place it inside ServerScriptService? I’m only starting to learn scripting because I have a lot of time due to Lockdown.

Yeah to get the gui though you would need a code like this.

local gui = player.PlayerGui:WaitForChild("GuiName")

Wouldn’t it be better and easier to do just if plr.Team == teamBlack then?

Yeah same thing. Kind of forgot how teams work. Both do the same thing though.

Yeah I know, it was just an idea to make the code look cleaner, but your should work fantastically :grinning:

1 Like

What about

local teamBlack = -- get team black

What do I need to do for that?

You can loops through the players and their teams,

for i,Player in pairs(game.Players:GetPlayers()) do
   if Player.Team ~= game.Teams.TeamName then
Player:FindFirstChild("PlayerGui").MorphSelection:Destroy()
end
end

Something like this

local team = game.Teams:WaitForChild("TeamName")

1 Like

In the Script Analysis tab, should those errors be ignored or do I need to do something tocorrect them?

local teamBlack = game.Teams:WaitForChild("TeamName")

game.Players.PlayerAdded:Connect(function(plr)
     if plr.TeamColor == teamBlack.TeamColor then
         local gui = plr.PlayerGui:WaitForChild("TeamName")
         gui.Enabled = false
     end
end)

Use that it should fix it. That is my fault player was not defined until the function so you have to add that part into the function!

1 Like

Actually it would be better to do this code:

local teamBlack = – get team black
local gui = – get gui
game.Players.PlayerAdded:Connect(function(plr)
    if plr.Team == teamBlack then
        gui.Enabled = false
    end
    plr:GetPropertyChangedSignal("Team"):Connect(function()
        if plr.Team == teamBlack then
            gui.Enabled = false
        end
    end)
end)

Just to make it still checking if player’s team isn’t the black one. The code you made checked it just when the player joined, if the player would change his team, then it wouldn’t disable the GUI for him.

Yes but make sure you define gui inside the function!

1 Like
local teamBlack = game.Teams:WaitForChild("Arrested")
local gui = player.PlayerGui:WaitForChild("MorphSelection")

game.Players.PlayerAdded:Connect(function(plr)
    local gui = plr.PlayerGui:WaitForChild("MorphSelection")
    if plr.Team == teamBlack then
        gui.Enabled = false
    end
    plr:GetPropertyChangedSignal("Team"):Connect(function()
        if plr.Team == teamBlack then
            gui.Enabled = false
        end
    end)
end)

Use this code and it will work right, as you want it to be working :smiley:

1 Like

Whoops did some mistake, LocalPlayer doesn’t exist in normal script, edited the code.

Player has not been defined yet, what do I need to do for now?

I’ve edited the code, try using the new one.

Also wait, no, don’t realised one more mistake, let me fix it for you :slight_smile:

local teamBlack = game.Teams:WaitForChild("Arrested")

game.Players.PlayerAdded:Connect(function(plr)
    if plr.Team == teamBlack then
        local gui = plr.PlayerGui:WaitForChild("MorphSelection")
        gui.Enabled = false
    end
    plr:GetPropertyChangedSignal("Team"):Connect(function()
        if plr.Team == teamBlack then
            local gui = plr.PlayerGui:WaitForChild("MorphSelection")
            gui.Enabled = false
        end
    end)
end)

Yeah, this one should work.