Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Adding/Subtracting Color3s? [Re-Edited]

Asked by 10 years ago
Edited by JesseSong 4 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

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

0
Please be more specific.What do you mean? Perhaps give an example of what you're trying to accomplish? AmericanStripes 610 — 10y
0
Added FromLegoUniverse 264 — 10y
0
Ah. Thank you. AmericanStripes 610 — 10y
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] JesseSong 3916 — 4y

1 answer

Log in to vote
1
Answered by 10 years ago

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

0
Works, thanks FromLegoUniverse 264 — 10y
Ad

Answer this question