Hey all! I am creating a team script, and I have no idea how to set the teams from the group. I also have set spawns. I have tried searching for tutorials but no luck. I know that remote events are required in order to change teams (unless that is for client scripts only), but I have no idea. Here is my code:
local gID = 15353961
game.Players.PlayerAdded:Connect(function(player) -- leaderstats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local KOs = Instance.new("NumberValue")
KOs.Name = "KOs"
KOs.Parent = leaderstats
KOs.Value = 0
local WOs = Instance.new("NumberValue")
WOs.Name = "WOs"
WOs.Parent = leaderstats
WOs.Value = 0
end)
game.Players.PlayerAdded:Connect(function(player) -- teams
local teams = game:GetService("Teams")
if player:GetRoleInGroup(gID) == "Basic Combat Training" then
player.Team = teams.BCT
end
if player:GetRoleInGroup(gID) == "Enlisted" then
player.Team = teams.Enlisted
end
if player:GetRoleInGroup(gID) == "Officers" then
player.Team = teams.Officers
end
if player:GetRoleInGroup(gID) == "headquarters" then
player.Team = teams.Headquarters
end
if player:GetRoleInGroup(gID) == "Chairman of the Joint Chiefs of Staff" then
player.Team = teams.Headquarters
end
------
local BS = game.Workspace.BCT.Spawn.Spawns:GetChildren()
local E2S = game.Workspace.E2Spawn.Spawns:GetChildren()
if player.Team.Name == "BCT" then
player.Character:WaitForChild("HumanoidRootPart").CFrame = BS[1].CFrame
end
if player.Team.Name == "Enlisted" then
player.Character:WaitForChild("HumanoidRootPart").CFrame = E2S[1].CFrame
end
if player.Team.Name == "Officers" then
player.Character:WaitForChild("HumanoidRootPart").CFrame = E2S[1].CFrame
end
if player.Team.Name == "Headquarters" then
player.Character:WaitForChild("HumanoidRootPart").CFrame = E2S[1].CFrame
end
end)
Hello, You may change your code from player.Team = teams.Officers to player.TeamColor = BrickColor.new(“team color”)
Here you can try this code:
game.Players.PlayerAdded:Connect(function(player) -- teams
local teams = game:GetService("Teams")
if player:GetRoleInGroup(gID) == "Basic Combat Training" then
player.TeamColor = BrickColor.new("Team Color") ---- Like ("Really Red")
end
if player:GetRoleInGroup(gID) == "Enlisted" then
player.TeamColor = BrickColor.new("Team Color")
end
if player:GetRoleInGroup(gID) == "Officers" then
player.TeamColor = BrickColor.new("Team Color")
end
if player:GetRoleInGroup(gID) == "headquarters" then
player.TeamColor = BrickColor.new("Team Color")
end
if player:GetRoleInGroup(gID) == "Chairman of the Joint Chiefs of Staff" then
player.TeamColor = BrickColor.new("Team Color")
end
And the below of the player spawn system, you can set in the SpawnLocation:
local gID = 15353961
game.Players.PlayerAdded:Connect(function(player) -- leaderstats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local KOs = Instance.new("NumberValue")
KOs.Name = "KOs"
KOs.Parent = leaderstats
KOs.Value = 0
local WOs = Instance.new("NumberValue")
WOs.Name = "WOs"
WOs.Parent = leaderstats
WOs.Value = 0
end)
game.Players.PlayerAdded:Connect(function(player) -- teams
local teams = game:GetService("Teams")
if player:GetRoleInGroup(gID) == "Basic Combat Training" then
player.TeamColor = BrickColor.new("Cyan") ---- Like ("Really Red")
end
if player:GetRoleInGroup(gID) == "Enlisted" then
player.TeamColor = BrickColor.new("Shamrock")
end
if player:GetRoleInGroup(gID) == "Officers" then
player.TeamColor = BrickColor.new("Cool yellow")
end
if player:GetRoleInGroup(gID) == "headquarters" then
player.TeamColor = BrickColor.new("Deep orange")
end
end)
Keep in mind that this is a server script inside of SSS.