Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't the for loop ever start?

Asked by 9 years ago

so for some reason it prints found but never prints (buttons.Name). Theres stuff in buttons but it never goes through the loop.

Items = {}
wait(1)
script.Parent:WaitForChild("Buttons")
local buttonchildren = script.Parent.Buttons:GetChildren()
repeat wait() until buttonchildren ~= nil
print("found")

for i,buttons in pairs(script.Parent.Buttons:GetChildren()) do --Never does this
    print(buttons.Name)
    if buttons:FindFirstChild("Head") then
            local Item = script.Parent.BuyableItems:FindFirstChild(buttons.Item.Value)
            if Item ~= nil then
                Items[Item.Name] = Item:Clone()
                Item:Destroy()
            else
                print("Button"..buttons.Name.."is missing and being removed")
            buttons.Head.CanCollide = false
            buttons.Head.Transparency = 1
            end
            buttons.Head.Touched:connect(function(hit)
                print("...")
                if hit.Parent.Humanoid and hit.Parent.Humanoid.Health > 0 then
                    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
                    local money = game.ServerStorage:FindFirstChild(player.Name)
                    local NeededObject = script.Parent.BuyableItems:FindFirstChild(Item.Value)
                    if player.Name == script.Parent.Owner.Value then
                        if NeededObject then
                            if money.Value >= buttons.Parent.Cost then
                            money.Value = money.Value - buttons.Parent.Cost
                            Items[buttons.Item.Value].Parent = script.Parent.PurchasedItems
                        end
                        buttons.Head.Transparency = 1
                        buttons.Head.CanCollide = false
                    end
                end
            end
        end)
    end
end

Answer this question