How ican fix code index nil with

for  _, PartsCriminal in FolderPartCriminal:GetChildren() do
	PartsCriminal.Touched:Connect(function(plr)
		local Player = game:GetService("Players"):GetPlayerFromCharacter(plr.Parent)
		if Player.Team == Police then
			print("Player Cant Be Criminal")
			else
			Player.Team = Criminal
		end
	end)
end

1 Like

usually occurs when you try to access a property or method on a nil value. In your code, the potential cause of this error could be the Player.Team line, where you’re trying to access the Team property of the Player object

for _, PartsCriminal in pairs(FolderPartCriminal:GetChildren()) do
    PartsCriminal.Touched:Connect(function(plr)
        local Player = game:GetService("Players"):GetPlayerFromCharacter(plr.Parent)
        if Player then
            if Player.Team == Police then
                print("Player Can't Be Criminal")
            else
                Player.Team = Criminal
            end
        end
    end)
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.