Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

hit = nil?

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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

Ad
Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago
Edited 2 years ago

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)

Answer this question