Need help selecting 20 objects in a single folder

Hey guys, I am making a game that generates a grid of tiles, and I was wondering how I would be able to randomly select exactly 20 of those tiles, I’ve tried to use some solutions, but none of them work.

Any help will be appreciated.

local map = workspace.map
local all = map:GetChildren()

local randomTile = all[math.random(20,#all)]

randomTile.BrickColor = BrickColor.new("Black")

use a for loop,

local map = workspace.map
local all = map:GetChildren()

for index, grid in pairs(all) do
 grid.BrickColor = BrickColor.new("Black")
end

You can use a for loop for that.

Example:

local map = workspace:WaitForChild('map')
local all = map:GetChildren()

for i=1,20 do
	local randomTile = all[math.random(1,#all)]
	randomTile.BrickColor = BrickColor.new('Black')
end
2 Likes

Thanks for the help, it worked!

1 Like