How do I make a color block game?

Hello,

I want to make a color block game since they are very popular on roblox right now. I currently have a round system but need a way to make the color block system e.g. making different colors dissapear except for one color each time and displaying this in a gui. Does anyone have any tips on how I can achieve this.

image

Thanks,
MarvelousMatty

local chosenColor = Color3.fromRGB(255,255,255)

for _, block in blocksFolder:GetChildren() do
	if block.Color ~= chosenColor then
		block.Transparency = 1
		block.CanCollide = false
	end
end
task.wait(5)
for _, block in blocksFolder:GetChildren() do
	if block.Color ~= chosenColor then
		block.Transparency = 0
		block.CanCollide = true
	end
end

Something as simple as this would work. I’m sure there’s ways for this to be more efficient though.
(edit: got the conditions the wrong way round, sorry)

1 Like

Hi,

Thanks for your help but for some reason all the blocks disappear when I run the game? There are no errors in the output.

This is my workspace.
image

This is the code I used. I changed it a bit but maybe I’ve done something wrong?
image

Also do you know if I’m able to have it select colors randomly but only from a select amount e.g just blue red or green?

make a list of colours as Color3 values.

colours = {colourvalue1, colourvalue2}

then call math.random() on it

randomcolour = colours[math.random(1, #colours)]
2 Likes

Also, this’ll only “run” once because the chosen colour is fixed. if you want it to go multiple times, use the randomcolour stuff i posted above.

Thank you for your help guys :slight_smile:

pls give the solution to @TestyLike3 they basically did everything, i just told you how to get random colours…

1 Like

I know you came up with a solution but I was doing something like what your doing that uses what A lot of people above said. I thought I would share as it does have a fade animation, though not requested, but if you want it here it is:

local FolderOfParts = game.Workspace.ColorChangingParts
local Colors = {Color3.fromHex("#00ff00"), Color3.fromHex("#f8f8f8"), Color3.fromHex("#0000ff")}

local function FadeAnimation(part, TransparentNum)
	local TweenService = game:GetService("TweenService")
	local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
	TweenService:Create(part, info, {Transparency = TransparentNum}):Play()
end

while true do
	task.wait(5)
	local PickRandom = Colors[math.random(1, #Colors)]
	for i, ColorParts in ipairs(FolderOfParts:GetChildren()) do

		if ColorParts:IsA("BasePart") and ColorParts.Color ~= PickRandom then
			ColorParts.CanCollide = false
			coroutine.wrap(FadeAnimation)(ColorParts, 1)
		end
	end
	task.wait(5)
	for i, ColorParts in ipairs(FolderOfParts:GetChildren()) do
		if ColorParts:IsA("BasePart") then
			ColorParts.CanCollide = true
			coroutine.wrap(FadeAnimation)(ColorParts, 0)
		end
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.