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

I got a "Attempt to index nil with FindFirstChild" error on my dialog script, can someone help?

--I keep getting this error and I don't get what's happening. All I know is that its in this line of code.

`
local HumanoidRootPart = NPC:FindFirstChild("HumanoidRootPart")  
	
**local ProximityPrompt = HumanoidRootPart:FindFirstChild("ProximityPrompt")**
	
if HumanoidRootPart and ProximityPrompt then 						ProximityPrompt.ObjectText  = NPC.Name 
ProximityPrompt.ActionText = "Talk to".. NPC.Name `

--script surrounded with '**' is the one not working.

3 comments

0

Is NPC referenced anywhere in the script?

0

Yes.

0

Csn someone please help

1 answer

Usually "Attempt to index nil" happens if something hasn't loaded in yet, Maybe try changing

:FindFirstChild()

to

:WaitForChild()

WaitForChild should be self-explanatory, It waits for a child with said name to load in. FindFirstChild will find the first child with said name, if there's none. It will return "Nil"

I also realised you've not told the script what "NPC" refers to, so that also may be why it's returning nil.

Try making a variable for that as well.

local NPC = game.Workspace:WaitForChild("  ") --Insert NPC Name here.
local HumanoidRootPart = NPC:WaitForChild("HumanoidRootPart")
local ProximityPrompt = HumanoidRootPart:WaitForChild("ProximityPrompt")

Hopefully one of these answers helped.

2 comments

0

Said "Infinite yeild possible on Local NPC = game.Workspace:WaitForChild("SusMan")

0

Is there an NPC named SusMan?

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