Does anyone know how to "add" color3s together like you can do with Vector3s?

  1. What do you want to achieve? Keep it simple and clear!
    basically what I want to do is make a Part and PointLight more brighter and saturated everytime I right-click
  2. What is the issue? Include screenshots / videos if possible!
    when I try it gives me [path to script]:7: attempt to perform arithmetic (add) on Color3
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I did try to look for solutions on the DevHub, however I couldn’t find my problem
    here is the script if you need it:
game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		local handleh, handles, handlev
		local handleh, handles, handlev = Color3.toHSV(script.Parent.Handle.Color)
		if handlev >= 0.6235294342041016 then return end
		if script.Parent.Handle.PointLight.Brightness >= 1 then return end
		script.Parent.Handle.Color += Color3.fromRGB(0, 12.23, 8.07)
		script.Parent.Handle.PointLight.Brightness += 0.075
		script.Parent.Handle.Sound:Play()
	end
end)
1 Like

instead of RGB try using HSV, and adjusting the saturation and lighting that way

it still gives me [path]:7: attempt to perform arithmetic (add) on Color3 and number

RGB is red,green,blue HSV is hue,saturation,and value, by using HSV you can set the color and then control the lighting easier instead of manually adjusting it with RGB

something like this

light.Color = Color3.fromHSV(hue, saturation, value)

you can increase the ‘saturation’ and ‘brightness’ with the value and saturation values

it works almost identical to RGB in terms of coding

You are receiving this error because you cannot directly add colors by doing .Color += num. Instead, you can break down the color into its three components, R, G, and B, and increment those values independently.

The .Color property in specific gives you a number from 0-1 representing how much of each value is used. In practice, we want values from 0-255, because we are more familiar with that as a representation of RGB.

An implementation could look like this:

local part = workspace.Baseplate
print(part.Color)
-- Prints 0.356863, 0.356863, 0.356863

print(part.Color.R * 255, part.Color.B * 255, part.Color.G * 255)
-- Prints 91, 91, 91 (more or less)

So to increment a parts color:

local increment = 10

-- Assuming we're using the same part as before:
local r = math.floor(part.Color.R * 255) + increment
local g = math.floor(part.Color.G * 255) + increment
local b = math.floor(part.Color.B * 255) + increment

part.Color = Color3.fromRGB(r, g, b)

heres a better example, just like RGB,HSV works almost identical in terms of coding, except HSV modifys different aspects of color

heres a example of modifying the value

RobloxStudioBeta_GqRgoPJ7DB

this is really simple to do

    while true do
        value = value + 0.01
        light.Color = Color3.fromHSV(1, 1, value)
        task.wait()
    end

hope this helps!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.