Fixing team script

  1. What do you want to achieve?

I have this team script but when I change the team it makes it so the players team color changes, but they’re not actually on the team. [Like if they go from red to blue, they’ll still spawn on red]

  1. What solutions have you tried so far?

Put the “Plyr.TeamColor = BrickColor.new(“Bright red”)” in server script and it works, but I want it to work for many teams not just Bright red

StarterGui script


script.Parent.MouseButton1Click:Connect(function()
	if Plyr:GetRankInGroup(11225064) >= 1 then
		game.ReplicatedStorage.TeamChangeEvent:FireServer()
		Plyr.TeamColor = BrickColor.new("Bright red")
	end
end)

Server script

game.ReplicatedStorage.TeamChangeEvent.OnServerEvent:Connect(function(plr)
	plr:LoadCharacter()
end)

If you can help, thank you!

The issue with your current script is that you’re only changing the player’s TeamColor , but not their actual Team . You need to change the player’s team to actually change the team they spawn on. Here’s an updated version of your code that should work:

StarterGui Script:

script.Parent.MouseButton1Click:Connect(function()
    if Plyr:GetRankInGroup(11225064) >= 1 then
        game.ReplicatedStorage.TeamChangeEvent:FireServer()
    end
end)

Server Script:

game.ReplicatedStorage.TeamChangeEvent.OnServerEvent:Connect(function(plr)
    local newTeam = game.Teams.BlueTeam -- Change this to the team you want to switch to
    plr.Team = newTeam
    plr.TeamColor = newTeam.TeamColor
    plr:LoadCharacter()
end)

The issue with your current script is that you’re only changing the player’s TeamColor , but not their actual Team . You need to change the player’s team to actually change the team they spawn on. Here’s an updated version of your code that should work:

StarterGui Script:

luaCopy code

script.Parent.MouseButton1Click:Connect(function()
    if Plyr:GetRankInGroup(11225064) >= 1 then
        game.ReplicatedStorage.TeamChangeEvent:FireServer()
    end
end)

Server Script:

luaCopy code

game.ReplicatedStorage.TeamChangeEvent.OnServerEvent:Connect(function(plr)
    local newTeam = game.Teams.BlueTeam -- Change this to the team you want to switch to
    plr.Team = newTeam
    plr.TeamColor = newTeam.TeamColor
    plr:LoadCharacter()
end)

In this updated script, we are now setting the player’s actual Team to the team you want to switch to, as well as updating their TeamColor . This should properly change the player’s team and the team they spawn on. Note that you’ll need to change game.Teams.BlueTeam to the actual team you want to switch to.

You should always handle changing teams on the server. Also this is very exploitable. You might want to do the checks (if the player is in the group) on the server not the client.