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.
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)
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
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.
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