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

Adding/Subtracting Color3s? [Re-Edited]

Is there a way to add/subtract Color3 values to BackgroundColor3 values in GUI items?

Addition:


local Pixels = Leg1:GetChildren()

	for i = 1, #Pixels do

		Pixels[i].BackgroundColor3 = Color3.new(256,256,256) + Pixels[i].BackgroundColor3

	end

##Error Code:

14:01:06.842 - Plugin_144415441.SkinModelPlugin:122: attempt to perform arithmetic on a userdata value

4 comments

0

Please be more specific.What do you mean? Perhaps give an example of what you're trying to accomplish?

0

Added

0

Ah. Thank you.

0

When paraphrasing lua code, make sure you encode your code in a code block. [I know this question is 6 years old as of November 7 2020, I just edited the question because the poster didn't use a code block properly]

1 answer

✓ Accepted answer

To do this, we need to first understand what Color3 is.

Wiki Definition: A real-valued RGB color tuple, with elements ranging from [0,1]. The Color3 data type is often used in setting the colors of objects that aren't related to bricks, such as GUIs, Sparkles, etc.

RGB (Red, Green, Blue) are the 3 main colors in ROBLOX. Messing with the Red, Green, and Blue values, is what gives you colors such as Pink, Yellow, Etc...

Knowing that, we can move on to how setting a Color3 works;

script.Parent.BackgroundColor3 = Color3.new(Red, Green, Blue)

Knowing that Color3's are setup like that, we can now try to subtract each value:

game.StarterGui.ScreenGui.Frame.BackgroundColor3 = Color3.new((game.StarterGui.ScreenGui.Frame.BackgroundColor3.r - 1)/255, (game.StarterGui.ScreenGui.Frame.BackgroundColor3.g - 1)/255, (game.StarterGui.ScreenGui.Frame.BackgroundColor3.b - 1)/255)

Sources: http://wiki.roblox.com/index.php?title=Color3

1 comment

0

Works, thanks

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