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

How do you loop this code because nothing seems to be working?

Asked by 3 years ago

Basically im trying to make a simple maze where there are walls lined up in rows and randomly 10 of the 27 will be seen. This is my script right now.

local Parts = workspace.Maze:GetChildren() for i, v in pairs(Parts) do math.randomseed(tick()) local RandomPart = Parts[math.random(1,#Parts)]

function invisible()
    RandomPart.Transparency = 0
    RandomPart.CanCollide = true
end
invisible()

end

So how would I make this for loop work. Thanks!

1 answer

Log in to vote
0
Answered by
Speedmask 661 Moderation Voter
3 years ago

table.remove() could help. this is because it will remove the wall from the list of walls and return it, so you do not change the same wall twice.

local N_VISIBLE = 10

local walls = workspace.Maze:GetChildren()
for _ = 1, N_VISIBLE do
    local wall = table.remove(walls, math.random(#walls))
    wall.Transparency = 0
    wall.CanCollide = true
end

using a loop that runs N_VISIBLE times, which is 10, it gets and removes a random wall from the list. then it makes it visible and whatever.

0
thanks DAB_VADER21 4 — 3y
Ad

Answer this question