Index nil 'Team'

When a player steps on a point, that point turns to the team. Color and name. Now it works sometimes. But sometimes it gives me an error:

It works at first for a few people, but then it breaks…

Code:

point1.Touch.Touched:Connect(function(hit)
	if not debounce1 then
		debounce1 = true
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if humanoid ~= nil then
			local player = Players:GetPlayerFromCharacter(hit.Parent)
			if player.Team ~= nil then
				if player.Team == Teams.British then
					-- Code
				elseif player.Team == Teams.French then
					-- Code
				end
			end
		end
		wait(1)
		debounce1 = false
	end
end)

You need to check if player is not nil before accessing any properties inside it

if player and player.Team ~= nil then
2 Likes

Not in all cases when the event is fired that you’ll find a player, because an object could touch it

if player and player.Team ~= nil then
2 Likes