I want a script so say BlockA is Green and BlockB is Blue, BlockB then touches BlockA, BlockA turns blue. But if BlockA was then to change colour, BlockB would be the same?
How do I make a script changes the colour of a brick to whatever it touches? [SOLVED]
1 answer
The color of a part is specified by its BrickColor property.
To get or set the color of a part, we get / set its BrickColor property.
The brick you want to change colors I call colorblock here; it could be script.Parent or workspace.Flashing or anything else you want.
When something touches colorblock, it fires its Touched event.
When the Touched event fires, it passes a parameter of the part touching colorblock. We get that touching part's BrickColor, and set colorblock's BrickColor to that.
It could look like this:
function BlockTouched(partTouching)
local newColor = partTouching.BrickColor;
colorblock.BrickColor = newColor;
-- `partTouching` is a parameter
-- passed that is the part that touched
-- `someblock`.
-- We just copy its `BrickColor` to `someblock`'s `BrickColor`.
end
colorblock.Touched:connect(BlockTouched);
Where someblock is a reference to the brick which will change color.
If we want to ignore certain touches, like, for instance, the base plate, we would have to check whether or not the object is one we want (or alternatively anchor it, so that it doesn't touch other anchored objects):
function BlockTouched(partTouching)
if partTouching.Name ~= "BasePlate" then
local newColor = partTouching.BrickColor;
colorblock.BrickColor = newColor;
-- Ignore parts named BasePlate
end
end
colorblock.Touched:connect(BlockTouched);
Or we could also check that partTouching isn't anchored:
if not partTouching.Anchored then
(although this may not be what you want)
This discussion is preserved as it was. New answers, comments, and votes are closed.

6 comments
I still don't get it :P
I edited it to my needs yet it still doesn't work...
I tested just to make sure. It works completely.
Made a quick change. It works perfect now! (Needed to add a local colorblock)
But now the baseplate affects it...
Yes, because this doesn't care what touches it. I will amend this answer showing a way to exclude certain parts.