Find First Child Error

I am trying to make a tycoon and am using Zednov’s Tycoon Kit (search ‘Zed’s Tycoon Kit’ in the toolbox under ‘Models’. It is by Zed_Gamer) to help me do this. However, I am having an error with the following script (no, no errors actually appear):

local PartCollector = script.Parent -- Note: there are TWO part collectors with the same name
local Conveyor = script.Parent.Parent.Parent.PurchasedObjects:FindFirstChild("RedRainbowConveyor")
PartCollector.Transparency = 1
PartCollector.CanCollide = false
script.Parent.PartProcessor.Disabled = true -- the script that is disabled is a drop processing script.
if script.Parent.Parent.Parent.PurchasedObjects:FindFirstChild("RedRainbowConveyor") ~= nil then -- if the red rainbow conveyor is purchased
	PartCollector.Transparency = 0
	PartCollector.CanCollide = true
	script.Parent.PartProcessor.Disabled = false
end

The error is that when this conveyor (the RedRainbowConveyor) is purchased, the part collector attached to it does not appear. Dose anyone here know why? If you do, will you tell me how to fix it?

You can just do:

if Conveyor then
    --code
end

I already tried that and that has failed. I also tried

if Conveyor ~= nil then
      --code

and that didn’t work either.

Could you maybe show your hierarchy? That would give us a better idea as to what is going on.

You can try replace the FindFirstChild with WaitForChild

1 Like

Thank you TheMirrorGameCreator. I fixed the problem because of you. Oh, and here is the improved code:

local PartCollector = script.Parent -- Note: there are TWO part collectors with the same name
PartCollector.Transparency = 1
PartCollector.CanCollide = false
local Conveyor = script.Parent.Parent.Parent.PurchasedObjects:WaitForChild("RedRainbowConveyor")
script.Parent.PartProcessor.Disabled = true -- the script that is disabled is a drop processing script.
if Conveyor then -- if the red rainbow conveyor is purchased
	PartCollector.Transparency = 0
	PartCollector.CanCollide = true
	script.Parent.PartProcessor.Disabled = false
end