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

hit = nil?

Workspace.StaffDoor.Part.Script:7: attempt to index nil with 'Parent'

local door = script.Parent
local team = "Pharmacist"

door.Touched:connect(function(plr, hit)
    print(hit)
    
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        if plr.Team == game.Teams[team] then
            door.CanCollide = false
            door.Transparency = 0.5
            wait(1)
            door.CanCollide = true
            door.Transparency = 0
        end
    end
end)

it prints nil

2 answers

Try this script place it in your part that is acting like door.

letinTeam = game.Teams:findFirstChild("Bright red Team")--put colour of the team that is Pharmacist 

teamycolor = letinTeam.TeamColor



local Door = script.Parent



function onTouched(hit) 

	print("Door Hit") 

	local human = hit.Parent:findFirstChild("Humanoid")

        local player = game.Players:findFirstChild(hit.Parent.Name) 

	if (human ~= nil ) then 

		if player.TeamColor == teamycolor then --the shirt 

			Door.Transparency = 0.67 

			Door.CanCollide = false 

			wait(4) -- this is how long the door is open 

			Door.CanCollide = false 

			Door.Transparency = 0.67

			-- a human has touched this door! 

			print("Door touched") 

			-- test the human's name against the permission list 

		else human.Health = -100 -- delete this line of you want a non-killing Team door 

		end 

	end 

end 



script.Parent.Touched:connect(onTouched)

Hope this helps

Touched Connection does not give you a player remove it and it should work what you should be doing to get the player is

local TouchPart = Part
local PlayerDoorTeam = "Pharmacist"
local Players = game:GetService("Players")
local Team = game:GetService("Teams")
TouchPart.Touched:Connect(function(Hit)
	local player = Players:GetPlayerFromCharacter(Hit.Parent)
	if player then
		if Player.Team == Team[PlayerDoorTeam] then
			door.CanCollide = false
			door.Transparency = 0.5
			wait(1)
	 		door.CanCollide = true
			door.Transparency = 0
		end
	end
end)

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