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

Re-stating; How can i find multiple children of a child using FindFirstChild?

Asked by 7 years ago

So my last question I accidentally made it seem like I was trying to do something else.. I am not trying to target multiple children actually. I am trying to target a child of several different children.

local wasTouched = false
local npcScript = game.Workspace:FindFirstChild("PathNPC").NPC:FindFirstChild("Walk")
part.Touched:Connect(function(hit)
    if not wasTouched then
        wasTouched = true
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid then
            npcScript.Disabled = false
        end
        wasTouched = false
    end
end)

This is the script I am trying to fix.

local npcScript = game.Workspace:FindFirstChild("PathNPC").NPC:FindFirstChild("Walk")

This is what I believe to be my error. here I tried to target the script "Walk" but I am not experienced with lua at all.

What am I doing wrong? The script is under Workspace, then PathNPC, then NPC. / Its parent is NPC, NPC's parent is PathNPC, and PathNPC's parent is Workspace.

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Problem was that if you run that code at the start of the game, the children may have not had enough time to be created so FindFirstChild("childName") wont find anything.

Do you need to confirm that the npcScript is a children of game.Workspace.PathNPC.NPC ? If not just type:

local npcScript = workspace:WaitForChild("PathNPC"):WaitForChild("NPC"):WaitForChild("Walk")
0
thanks! I'll try this. EtherealTrin 45 — 7y
Ad

Answer this question