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
4 comments
I approve this answer
Thanks. That means a lot to me.
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.
Ask a new question. This one has been answered. I would also love you if you accepted my answer.