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

how to say "everything but a certain brick"?

Asked by 9 years ago

so say out of 10 bricks, you choose one brick by math.random, and you want to destroy the 9 bricks that aren't that one brick. how would you say that in lua?

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago
01--First determine your set of bricks
02local bricks = workspace.Bricks:GetChildren()
03 
04--Now chose one randomely
05local brick = bricks[math.random(1,#bricks)]
06 
07--Iterate through the table and remove the index if it doesn't match 'brick'
08for _,v in next,bricks do
09    if v ~= brick then
10        v:Destroy()
11    end
12end
Ad

Answer this question