Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making a block swap between two colors?

Okay, I thought this was easy, just edit a "random color" script for a block. Nope. It's not working. It's about 2 AM, so don't be surprised if it's a really dumb mistake.

brick = script.Parent
while true do
brick.BrickColor = "Industrial white"
wait(0.5)
brick.BrickColor = "Bright green"
wait(0.5)
end

Do I have to write "part" instead of "brick" because the piece is called Part?

...I'm very tired...

2 answers

✓ Accepted answer

You're using BrickColor wrong

To change a part's brick color, you have to do BrickColor.new().

Example,

brick = script.Parent
while true do
	brick.BrickColor = BrickColor.new("Industrial white")
	wait(0.5)
	brick.BrickColor = BrickColor.new("Bright green")
	wait(0.5)
end

Here's a link to the wiki on the subject.

Good Luck!

If I helped, please don't forget to accept my answer.

4 comments

0

I approve this answer

0

Thanks. That means a lot to me.

0

Thank you so much! Do you know a way to make parts from two different models match color change time, if one is spawned at a different time? I'm making a tycoon, and one purchase expands on the glowing, color changing part.

0

Ask a new question. This one has been answered. I would also love you if you accepted my answer.

Let's kick this off by answering your question.

Do I have to write "part" instead of "brick" because the piece is called Part?

The basics, When you define an object with a name, you can name the part anything you like, and same goes to the variable name.

Suppose you have a part called "Part" in workspace. The name of the part is "Part" Let's assume that you want to call the part by the name "Brick" in your script.

Brick = game.workspace.Part

Now, note that, game.workspace.Part and Brick, both point to the same object without the game. It's a way of making our work easier and make programming more fun.

Let's get to your real question now

So, How does one change/swap colours between two blocks?

Let's begin with defining the 2 parts and the colours.

local Part01 = game.Workspace.Part01
local Part02 = game.Workspace.Part02

local Colours = {"Bright red", "Bright blue"}

Great!, Note that I used an array to store my colours.

Let's make a function for re-usability

function SwapColours(Table) do
	Colour1 = Table[math.random(1, #Table:GetChildren())]
	repeat
		Colour2 = Table[math.random(1, #Table:GetChildren())] 
	until
		Colour2~=Colour1

	return Colour1, Colour2
end

Great, we just made a very simple function that takes in random colours and swaps them

Ok, All we need to do now is change the colours

local Part01 = game.Workspace.Part01
local Part02 = game.Workspace.Part02

local Colours = {"Bright red", "Bright blue"}


function SwapColours(Table) do
	Colour1 = Table[math.random(1, #Table:GetChildren())]
	repeat
		Colour2 = Table[math.random(1, #Table:GetChildren())] 
	until
		Colour2~=Colour1

	return Colour1, Colour2
end
while wait(2) do

	C1,C2 = SwapColours(Colours)
	
	Part01.BrickColor = BrickColor.new(C1)
	Part02.BrickColor = BrickColor.new(C2)
end

This is just one way of complicating a problem lol, jk anyways hope that helps

2 comments

0

That's not entirely what I was asking, but it does solve my unspoken question on how to make the blocks change together from white to green. Sort of. I'd have to tinker with it some more. Thank you. ^-^

0

Glad I helped in some way or the other. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.