Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Error: attempted to index nil with "Team", What is this?

script.Parent.Touched:Connect(function(hit)
	--Check for PLAYER
	if hit.Parent:FindFirstChild("Humanoid") then
		--Find out what team the player is on
		local Player = game.Players:GetPlayerFromCharacter(hit)
		--Execute code
		if Player.Team == "Evils" then
			script.Parent.Transparency = 1
			script.Parent.CanCollide = false
		end
	end
end)

I do not understand at all what happened, the team is perfectly valid

Also here is the error: 20:33:49.301 - Workspace.Map1.EssenceModel.Essence.Script:11: attempt to index nil with 'Team' It's line 11 which just says end

Can someone explain please?

3 comments

0

Put this in a code block please

0

Done, sorry

0

Well i guess this will not be answered... ;(

2 answers

Try this script, the problem probably was that something that was not a player was touching the part.

script.Parent.Touched:Connect(function(hit)
    --Check for PLAYER
	--Check if it is a person/player
	if game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then
       		--Find out what team the player is on
        	local Player = game.Players:GetPlayerFromCharacter(hit)
        	--Execute code
        	if Player.Team == "Evils" then
            		script.Parent.Transparency = 1
            		script.Parent.CanCollide = false
		end
        end
end)

1 comment

0

sorry if the code came out weird, its hard formatting it in the text box

It's because "Team" isn't a string, it's an object. Thus you just need to change the if statement that looks for the team to this:

if Player.Team == game.Teams.Evils then

1 comment

0

Also as a quick side note: what Fad said is also useful, since this script would run when anything with a humanoid touches it (e.g zombies or other entities you have in your game)

This discussion is preserved as it was. New answers, comments, and votes are closed.