Team Gui scrippt

I’m currently working on a system that assigns you to a random team when you join the game (Team Blue/Red). I’ve had the idea to add a gui with two side (Blue / Red) and the player will appear on the side according to the team he is on.

So if player1 is on the blue team, he’ll appear on the blue side, and if player2 is on the team red, he’ll appear on the red side.

So i dont know how to make this script, is it possible for someone to help me please. Thank you

2 Likes

here’s a basic outline

1 - Create the GUI
Create a UI with two sides (Blue and Red) using a ScreenGui and two Frame objects. Inside each frame, you can place images or labels to represent the players on each team.

2 - Team Assignment
In your game script in a PlayerAdded event handler assign players to a random team. Use the Teams service to manage teams.

local Teams = game:GetService("Teams")

-- Assuming you have Blue and Red teams already created in your game
local blueTeam = Teams["Blue"]
local redTeam = Teams["Red"]

game.Players.PlayerAdded:Connect(function(player)
    local randomTeam = math.random(2) == 1 and blueTeam or redTeam
    player.Team = randomTeam
end)

Update GUI Based on Team: In your PlayerAdded event handler, after assigning teams, you can update the GUI to reflect the player’s team. You can use the Player.Team property to determine which side they should appear on.

game.Players.PlayerAdded:Connect(function(player)
    local randomTeam = math.random(2) == 1 and blueTeam or redTeam
    player.Team = randomTeam
    
    -- GUI logic
    local playerGui = player:WaitForChild("PlayerGui")
    local gui = Instance.new("ScreenGui")
    gui.Name = "TeamGui"
    
    local teamFrame = Instance.new("Frame")
    teamFrame.Parent = gui
    teamFrame.Size = UDim2.new(0.5, 0, 1, 0)
    teamFrame.Position = UDim2.new(randomTeam == blueTeam and 0 or 0.5, 0, 0, 0)
    
    gui.Parent = playerGui
end)

This is a simple example lmk if you have any questions

3 Likes

where does the second script go? and what does it do?

1 Like

ServerScriptService or a ServerScript

1 Like

what does this script do, is it possble to explain?

1 Like

1 - create a new Script object within a ServerScriptService or a ServerScript object in the hierarchy.
2 - copy and paste the second script (the one that updates the GUI) into the new Script object.

both scripts should be located in the same location (a ServerScriptService or a ServerScript object) within your game hierarchy

1 Like