Attempt to index nil with 'Team'

I’ve tried many way’s until my script got broken out of nowhere and this is a new way I was trying but it’s not working fully… Can someone help me fix it?

local Team = game:GetService("Teams")["Republic"]
local Team2 = game:GetService("Teams")["Empire"]
function onTouch(hit)
	    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	    if player.Team == Team then
		script.Parent.CanCollide = false	
		wait(1)
		script.Parent.CanCollide = false
		---------
		if player.Team == Team2 then		
		local Humanoid = player:WaitForChild("Humanoid")	
		Humanoid.Health = 0
		--------------			
			end
	end
end
script.Parent.Touched:Connect(onTouch)
2 Likes

Try this :

local Team1= game:GetService("Teams")["Republic"]
local Team2 = game:GetService("Teams")["Empire"]
function onTouch(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player.Team.Name == Team1.Name then
			script.Parent.CanCollide = false	
			task.wait(1)
			script.Parent.CanCollide = false
		elseif player.Team.Name == Team2.Name then
			local Humanoid = player:WaitForChild("Humanoid")	
			Humanoid.Health = 0
		end
	end
end
script.Parent.Touched:Connect(onTouch)
1 Like

Alright I’m trying it right now

1 Like

It works now it’s saying this
Infinite yield possible on ‘Players.Tamegogeta13:WaitForChild(“Humanoid”)’

Oh, I know why :

replace it with :

local Humanoid = hit.Parent:WaitForChild("Humanoid")

this is what i did and it works now

local Team1= game:GetService("Teams")["Republic"]
local Team2 = game:GetService("Teams")["Empire"]
 function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") then
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player.Team.Name == Team1.Name then
		script.Parent.CanCollide = false	
		task.wait(1)
		script.Parent.CanCollide = false
	elseif player.Team.Name == Team2.Name then
		local character = player.Character or player.CharacterAdded:Wait()
		local Humanoid = character:WaitForChild("Humanoid")
		Humanoid.Health = 0
	end
end
  end
 script.Parent.Touched:Connect(onTouch)
1 Like

Yes, it is possible to get the humanoid by that way aswell. Good job

If I helped you ,mark it as a solution :slight_smile:

2 Likes

you did alot lol i knew some was but you did what i overlooked thanks soo much
and I been trying to do a anti-team kill with my tool to where if i switch teams it works regardless without setting it to one team then duplicating it for the other team

2 Likes