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

How would I make this if loop work? (2 FindFirstChild's)

if game.ReplicatedStorage.Quests:FindFirstChild(a.Value):FindFirstChild("CompletedBountyOn"..p.Name) then
end

Error: attempt to index a nil value

Since it has two :FindFirstChild()'s

p = LocalPlayer a = a value which is detected (String)

Is there a way to make this work without using two FindFirstChild's? I've tried using WaitForChild but that doesn't seem to be doing it..

Thanks in advance

3 comments

0

if game.ReplicatedStorage.Quests:FindFirstChild(a.Value):FindFirstChild("CompletedBountyOn"..p.Name) then

0

^ That's because it apparently didn't fully show

0

If condition* My bad :/

1 answer

✓ Accepted answer

FindFirstChild either returns the object you're looking for or it returns nil. nil:FindFirstChild("CompletedBountyOn"..p.Name) will obviously not work, but that's exactly what's happening.

You just have to do it separately.

a = object:FindFirstChild("child")
if a then
	b = a:FindFirstChild("child2")
	if b then
		--code
	end
end

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