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

If this returns nil, how do I make it select a new value?

Asked by 5 years ago

I'm trying to make it so a random brick out of 30 falls. It works, but after i=30 there's always lots of bricks left. How do I make it so if the brick has already fallen, the program picks a new brick instead of just skipping ahead?

for i = 1,30 do
    local randnum = math.random(1,30)
    for i,v in pairs(children) do --- A script that goes through all the children of your parent
        if i == randnum then
            if v.Parent ~= nil then
            v.Anchored = false --- V is representing the current child it is on.
            game:GetService("Debris"):AddItem(v,"3")
            v.Parent = game.workspace
            wait(0.1)
            end
        end
    end
end

Answer this question