I can't get the player to change the team when they hit the Team Color

When I have the player join the game, I have them click a button that lets them go to Red Team if they click it. When they click it from a local script, it sends the players team they selected, and I get an error in the console when I tried using a print function when I was diagnosing the problem.

Local Script:

redTeamButton.MouseButton1Click:Connect(function()

teamChanged:FireServer(redTeamButton.Name)

end)

Script:

local teams = game:GetService('Teams')

game.ReplicatedStorage.TeamChanged.OnServerEvent:Connect(function(Player, Team)
	print(Player .. "selected " .. Team)
	
	local playerToTeam = teams:FindFirstChild(Team).TeamColor
	Player.TeamColor = playerToTeam
	
	Player.Character.Humanoid.Health = 0
end)

Console:

image

Any ideas on how to fix this?

1 Like

Yes you are trying to make an instance with a string do this:

print(Player.Name .. "thing here" .. Team)
1 Like

Player.TeamColor is saved with BrickColor most of the time. Rewrite the script a bit to adjust to replace Player.TeamColor = playerToTeam to something along the lines of Player.TeamColor = BrickColor.new("What ever your color is") I’m assuming that you’re NOT changing to a .RGB value, based off the error.

You’re trying to concatenate player object with string, use Player.Name

1 Like

I send over the team color from the local script with the remote event, because it will be handling all 4 other teams when someone presses it. I don’t want to have it with 5 different scripts. I was able to get the team name with the print function, so the remote event is fine.

What value are you even sending. There’s a lack of too much context. For instance, there isn’t even a parent assigned to “redTeamButton”, so I can’t really figure out what the parent even is.

Here is what the explorer looks like, and the variables for the buttons for reference.

Image:

image

Button Variable:

local redTeamButton = script.Parent.DeployBackground:FindFirstChild('Red Team')