# Pick a random color, and destroy all parts that arent that color

1. What do you want to achieve? Like the title says I want to make a game where you have a color that is displayed and a lot of blocks, if you don’t get on the displayed color in 5 seconds every color that isn’t that color falls to the void (or simply disappears)

2. What is the issue? I’ve tried a lot of things and nothing really works.

3. What solutions have you tried so far? Looked everywhere

Main game script:

``````
local BrickColors = {"Really red","Deep orange","New Yeller","Dark blue","Hot pink","Reddish Brown","Lime green","Magenta"}

local lobbyLocation = game.Workspace.Lobby.Lobby2.Position + Vector3.new(0,3,0)
local gameLocation = game.Workspace.Lobby.Game.Position + Vector3.new(0,3,0)

local IntermissionTime = 3
local GameTime = 10
local function playGame()

end

local function beforeGame()
for i, v in pairs(ColorParts:GetDescendants()) do
if v:IsA("BasePart") then
if v.Name == "Part" then
v.Transparency = 0
local ChosenColor = BrickColors[math.random(1, #BrickColors)]
v.BrickColor = BrickColor.new(ChosenColor)
end
end
end
end

local function playIntermission()
for i, v in pairs(ColorParts:GetDescendants()) do
if v:IsA("BasePart") then
if v.Name == "Part" then
v.Transparency = 1
end
end
end
end

local function resetPlayers()
print("Players have been reset!")
for _, plr in pairs(game.Players:GetChildren()) do

plr.Character.HumanoidRootPart.CFrame = CFrame.new(lobbyLocation)
end
end

local function teleportPlayers()
print("Players were teleported!")
for _, plr in pairs(game.Players:GetChildren()) do

plr.Character.HumanoidRootPart.CFrame = CFrame.new(gameLocation)
end
end

while true do
resetPlayers()
playIntermission()
wait(IntermissionTime)
teleportPlayers()
beforeGame()
wait(GameTime)
playGame()
end``````

Which part of the script are you having trouble with?

Is some part of your code not working or is it you need help with detecting all bricks with a color

None of the script, it works fine but I just dont know how to do it

To detect all bricks with a specific color, try the following:

``````function findBricks(location, color)
for k,v in pairs(location:GetDescendants()) do
if v:IsA("BasePart") and (not v.Locked)  and v.BrickColor ~= color then
v:Destroy()
end
end
end
``````

Note: location would be a folder, model or the workspace, it will check for bricks recursively

2 Likes

But how would I say if it ISNT a color?

Oops, my mistake. I edited it now.

How would It only pick one block you step on and the others to destroy?