Setting teams to players via touching a brick

ive tried to set a team by having a player tp to a brick which changes their team but just doesnt change the team whatsoever
my script:

local Jteam = teams.Juggernaut
local Jmaxplayers = Jteam:GetPlayers()
local val = #Jmaxplayers

function onTouch(hit)
	if val == 1 then
		hit.Parent.Humanoid.MaxHealth = 100
		hit.Parent.Humanoid.Health = 100
		
		hit.TeamColor = BrickColor.new("Storm blue")
	end
	
	if val == 0 then
		hit.Parent.Humanoid.MaxHealth = 500
		hit.Parent.Humanoid.Health = 500
		
		hit.TeamColor = BrickColor.new("Persimmon")
	end
end

script.Parent.Touched:Connect(onTouch)

note: the tp code isnt meant to be in this script so basically it tps me to the brick but does not change the team
hit.TeamColor = BrickColor.new("Storm blue")

Hit is a basepart. It doesn’t have a team color property. Instead, do

game:GetService("Players"):GetPlayerFromCharacter(hit.Parent).TeamColor = BrickColor.new("Storm blue")

Also, in your onHit function you should add a check to make sure that the hit is a part of a character. You might not need that but it’s a good habit.

1 Like

thank you! i tried to use localplayer earlier but im guessing thats the issue with setting teams