Why does this brick not change colors?

updatedCode

I’ve made several changes making it a little bit better like checking for a player since anything can touch the part. The goal was when the part is touched, it changes colors. In the long run, I’d like to make a capture point system.

I’ve double checked the teams and the players team when the game starts. I am 100% positive the team information in the code is correct.

Somehow the if statement is still returning false.

1 Like

try this

local PointA = game.Workspace.PointA

function PointTouched(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local MainPlayerTeam = player.TeamColor
	
	if MainPlayerTeam == BrickColor.new("Black") then
		PointA.BrickColor = BrickColor.new("Black")
	end
end

PointA.Touched:Connect(PointTouched)
1 Like

hope this works in your code and have a great day

I tried it out and unfortunately no luck but I do appreciate the attempt. I’m not understanding what is wrong because the team color is 100% black.

u have to remove that code u have because its not write. use the code i have

and the script have to be in the part and not in server script service

1 Like

My fault I made a slight error when pasting in your code but I did replace mine originally with yours. Thank you for the solution.

Player.TeamColor uses the class BrickColor, not a string. The solution here is to change your if statement to if MainPlayerTeam == BrickColor.new("Black") then instead.

edit: I see that you got the solution but it doesn’t hurt to know why

1 Like

Thank you I really wanted to know why it wasn’t working. It felt like it was supposed to work and I was stuck on it for a little while as a newbie scripter. Much appreciated.

1 Like

can u mark it as solution?

This text will be blurred

It’s useful to read documentation so you can see if this is a problem in the future. For example, the reference page for this exact property reports it being BrickColor (vs string in this case), and can also give a brief rundown on the property if you’re unsure what it’s for. Roblox has a very strong documentation and I find it useful for a multitude of things personally

1 Like

This is going to error if ‘player’ is ‘nil’, error, attempt to index 'nil' with 'TeamColor'. You need to add if player then` to the function.

1 Like