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 8 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
8 years ago
--First determine your set of bricks
local bricks = workspace.Bricks:GetChildren()

--Now chose one randomely
local brick = bricks[math.random(1,#bricks)]

--Iterate through the table and remove the index if it doesn't match 'brick'
for _,v in next,bricks do
    if v ~= brick then
        v:Destroy()
    end
end
Ad

Answer this question