Attempt to index nil with 'TeamColor'

So, I was creating a team changing door, nothing much. It works but for some reason, I keep getting an error…

Screen Shot 2020-07-05 at 10.42.27 am

script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr.TeamColor ~= BrickColor.new("Pink") then
		plr.TeamColor = BrickColor.new("Pink")
	end
end)

Why is this?

You are assuming that a player always touches the part when this isn’t always the case. Guard your code with

if not plr then
    return
end
5 Likes