Attempt to index nil with FindFirstChild

Hi, my friend is trying to make a tycoon game and he’s getting this error:

Here’s the script:

--Buy Item/Dropper

for i,v in pairs(Buttons:GetChildren()) do
    local NewItem = BoughtItems:FindFirstChild(v.Item.Value)
    if NewItem ~= nil then
        Items[NewItem.Name] = NewItem:Clone()
        NewItem.Destroy()
    else
        v.ButtonPart.Transparency = 1 
        v.ButtonPart.CanCollide = false        
    end
    
    if v:FindFirstChild("Dependency") then
        coroutine.resume(coroutine.create(function()
            v.ButtonPart.Transparency = 1
            v.ButtonPart.CanCollide = false 
            if BoughtItems:WaitForChild(v.Dependency.Value, 10000) then
                v.ButtonPart.Transparency = 0
                v.ButtonPart.CanCollide = true 
            end
        end))
    end    

If this is line 26
local NewItem = BoughtItems:FindFirstChild(v.Item.Value)
Then BoughtItems is nil. You aren’t showing where you have it declared though, so I can’t help beyond that. If this isn’t the right line, then please label the line with the error.

2 Likes