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

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

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

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")

1 comment

0

thanks! I'll try this.

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