Greetings.
I have zero experience in scripting, I want to have a script that will change the color of a specific brick to the opposite color.
local Color = script.Parent.Color
--Inverse Color's Components
local r, g, b = 0,0,0
r = 255 - (Color.R*255)
g = 255 - (Color.G*255)
b = 255 - (Color.B*255)
script.Parent.Color = Color3.fromRGB(r,g,b)
This is a code I found after searching for a while.
My idea is a script which is put into Workspace that will affect all the bricks with a specific name
Are you looking for something like this:
local function InverseColor(Color: Color3)
return Color3.new(Color.B, Color.R, Color.G)
end
local function ChangeColorsForParts(NameOfParts: string)
for _, Part in pairs(workspace:GetDescendants()) do
if Part.Name ~= NameOfParts then continue end
Part.Color = InverseColor(Part.Color)
end
end
ChangeColorsForParts("The Name Of the parts you want changing colors")
You can change up the arrangement of the color swap if you’d like
Also, if you need anything explained, let me know
Hello, this actually works as intended, just not exactly as expected. I’d like to get an explanation on how I want this to function to work.
-
If I have a Part with the color Bright Yellow (245, 205, 48), the script I quoted above sends back Lapis (16, 42, 220)
-
The script you sent gives back the color Teal (48, 245, 205). Your script is accurate, but looking online the opposite of Bright Yellow is Lapis.
So maybe I am doing something wrong here?
*edit: May also add this is based in RGB colors, not Color3
Well, how do you intend on investing it, the script I gave just switches the order of the RGB values to be BRG
Do you have the formula for your inversion
Does this work (on mobile so I can’t test myself)
local function InverseColor(Color: Color3)
return Color3.new(1-Color.R, 1-Color.G, 1-Color.B)
end
local function ChangeColorsForParts(NameOfParts: string)
for _, Part in pairs(workspace:GetDescendants()) do
if Part.Name ~= NameOfParts then continue end
Part.Color = InverseColor(Part.Color)
end
end
ChangeColorsForParts("The Name Of the parts you want changing colors")
1 Like
Yes, this is what I expected it to be.
Thank you very much for the help provided! 
Cheers.
1 Like