Whenever a player changes a team, it also changes to others.
Server script:
local s = game.ReplicatedStorage.SwitchTeamO
local groupid = 12648144
game.Players.PlayerAdded:Connect(function(plr)
if plr:IsInGroup(groupid) then
s.OnServerEvent:Connect(function()
plr.TeamColor = BrickColor.new("Navy blue")
plr:LoadCharacter()
end)
end
end)
Client script:
local s = game.ReplicatedStorage.SwitchTeamO
script.Parent.MouseButton1Click:Connect(function()
s:FireServer()
end)
Do I need to use get players? Because I’m kinda confused about GetPlayers().
local s = game.ReplicatedStorage.SwitchTeamO
local groupid = 12648144
s.OnServerEvent:Connect(function(plr)
if plr:IsInGroup(groupid) then
plr.TeamColor = BrickColor.new("Navy blue")
plr:LoadCharacter()
end
end)
You shouldn’t use TeamColor, you can just use plr.Team. Fixed script:
local s = game.ReplicatedStorage.SwitchTeamO
local groupid = 12648144
local teamService = game:GetService("TeamService")
game.Players.PlayerAdded:Connect(function(plr)
if plr:IsInGroup(groupid) then
s.OnServerEvent:Connect(function()
plr.Team = teamService["TeamNameHere"]
plr:LoadCharacter()
end)
end
end)```
local s = game.ReplicatedStorage.SwitchTeamO
local groupId = 12648144
local teamService = game:GetService("Teams")
local groupTeam = teamService[""] --change team name inside the quotes
game.Players.PlayerAdded:Connect(function(plr)
if plr:IsInGroup(groupId) then
s.OnServerEvent:Connect(function()
plr.Team = groupTeam
plr:LoadCharacter()
end)
end
end)