I have the following code:
local door = script.Parent
local allowed = {"boogieboon", "someothername"}
door.touched:connect(function(hit)
local character = hit.Parent
if character.Humanoid then
for i,v in pairs(allowed) do
if character.Name == v then
door.Transparency = 1
door.CanCollide = false
wait(1)
door.Transparency = 0
door.CanCollide = true
end
end
end
end)
I was just wondering why the output keeps returning "Humanoid is not a valid member of Accessory" for line 6 even though I have an if statement that is supposed to deal with what to do if it doesn't have a humanoid in it? It's not a game-breaking problem but I would just like to know how to prevent the output from erroring since I'm trying to deal with this error in the if statement. Thanks, Any help is appreciated.

1 comment
when you index a child that is nil it errors, so use FindFirstChild in the if statement