Script seems to work with some buttons only (coroutine)

This script seems to be working but with only some buttons.
What should the script do:
When you step on the button, another button should appear after.

local TycoonModel = script.Parent.Parent
local items = {}
local BoughtItems = TycoonModel:FindFirstChild("BoughtItems")
local Buttons = TycoonModel:FindFirstChild("Buttons")
local DropperParts = TycoonModel:FindFirstChild("DropperParts")
local Scripts = TycoonModel:FindFirstChild("Scripts")
local Values = TycoonModel:FindFirstChild("Values")
local mainItems = TycoonModel:FindFirstChild("MainItems")

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.Button.Transparency = 1
		v.Button.CanCollide = false
		v.Button.BillboardGui.TextLabel.Visible = false
	end
	

	if v:FindFirstChild("Dependency")then
		coroutine.resume(coroutine.create(function()
            v.Button.Transparency = 1
            v.Button.CanCollide = false
			v.Button.BillboardGui.TextLabel.Visible = false
            if BoughtItems:WaitForChild(v.Dependency.Value, 111 ) then
                v.Button.Transparency = 0
                v.Button.CanCollide = true
				v.Button.BillboardGui.TextLabel.Visible = true
				
            end
        end))      
    end

Thanks in advance!

local TycoonModel = script.Parent.Parent
local BoughtItems = TycoonModel:FindFirstChild("BoughtItems")
local Buttons = TycoonModel:FindFirstChild("Buttons")

local Items = {}

for i, v in pairs(Buttons:GetChildren())do
	local NewItem = BoughtItems:FindFirstChild(v.Item.Value)
	if NewItem then
		Items[NewItem.Name] = NewItem:Clone()
		Items[NewItem.Name].Parent = workspace --set parent property?
		NewItem:Destroy()
	else
		v.Button.Transparency = 1
		v.Button.CanCollide = false
		v.Button.BillboardGui.TextLabel.Visible = false
	end

	if v:FindFirstChild("Dependency")then
		v.Button.Transparency = 1
		v.Button.CanCollide = false
		v.Button.BillboardGui.TextLabel.Visible = false
		if BoughtItems:FindFirstChild(v.Dependency.Value) then
			v.Button.Transparency = 0
			v.Button.CanCollide = true
			v.Button.BillboardGui.TextLabel.Visible = true
		end      
	end
end
1 Like

seems to be working thx for helping me out