How do I set RGB values separately?

No, not really…

I’m gonna go and try and make an example so it’s easier to understand, the way I’m explaining it is only confusing people and making things harder.

See ya’ll in a bit. :wave:

I think I understand what you mean, you want it so when the green and red lights are on then it will mix and they will both be purple?

So this is an example I threw together last minute.

I want a script that’s capable of this.

I don’t even know if it’s possible in Lua.

1 Like

You can’t set RGB values separately. You simply have to add a value of colour to the existing colour. For example, in the video, the buttons modify the colour of the block, right? So all you need to do is get the current R, G and B values from the existing part’s colour, then pass those to the new Color3.

-- For example, setting red
local CurrentColor = Color3.fromRGB(255, 255, 255)

-- When X button:
local CurrentColor = Color3.fromRGB(0, CurrentColor.G, CurrentColor.B)

-- When color button:
local CurrentColor = Color3.fromRGB(255, CurrentColor.G, CurrentColor.B)

Thanks, I’ll try that… :grimacing:

Okay, something’s not working…

function onClicked()

local CurrentColor = game.Workspace.screen.Color.Color3.fromRGB(255, 255, 255)

local CurrentColor = game.Workspace.screen.Color.Color3.fromRGB(255, CurrentColor.G, CurrentColor.B)

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

I see what you are trying to do.

If I get it right, you just want to add more red color value to the RGB. Like 2, 5, 5 when you click the red you get 3, 5, 5 then if you click again you get 4, 5, 5 and so on (the change can be changed)
I tried to do something with that. But the part.Color.r got me HSV value. I tried to play with that.

Before I knew it gave me HSV, I tried this for the red button:
part.Color = Color3.fromRGB(CurrentR+change, CurrentG, CurrentB)
I think you get my idea.

After I knew it gave me HSV, I tried this for the red button:
part.Color = Color3.fromGSV(CurrentR+change, CurrentG, CurrentB)
The change would need to be in HSV, it didn’t work out perfectly either.

I don’t have more brainpower, but maybe someone else here gets some ideas from my tries.

That’s because you define CurrentColor as 255, 255, 255 in the function itself, so it will always change the colour based on that value. You also aren’t supposed to define the variable a second time.

local CurrentColor = game.Workspace.screen.Color

function onClicked()
    CurrentColor = Color3.fromRGB(0, CurrentColor.G, CurrentColor.B)
    game.Workspace.screen.Color = CurrentColor
    -- If you set it to 255, it remains 255, assuming the start colour is 255-all
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Oh, great… What am I doing wrong now?

local CurrentColor = game.Workspace.screen.Color

function onClicked()

local CurrentColor = game.Workspace.screen.Color.Color3.fromRGB(0, CurrentColor.G, CurrentColor.B)

game.Workspace.screen.Color = CurrentColor

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Stop trying to change the code I gave you. That’s not how you use the function. Color3 is a datatype. Color doesn’t have a member property named Color3.

Add the function exactly as I gave it to you and try again. Also be sure to check your console so you’re aware of these errors and how to combat them. Things don’t work for a reason.

I feel like just giving up…

Apparently your script only changes the total color of the block, instead of changing values separately, which you stated in your first post. I completely misunderstood, apologies.

I think I’m just gonna have to find another extremely-convoluted solution to my problem until Roblox implements the ability to change values separately (which realistically, probably will never happen.)

Thanks for all the help.

local CurrentColor = game.Workspace.screen.Color

    function onClicked()
        CurrentColor = Color3.fromRGB(255, CurrentColor.G, CurrentColor.B)
        game.Workspace.screen.Color = CurrentColor
        -- If you set it to 255, it remains 255, assuming the start colour is 255-all
    end

    script.Parent.ClickDetector.MouseClick:connect(onClicked)

Huh? You’re starting to confuse me as to what you want. Yes, my code changes the color of the block based on the numbers you change around. Is this not what you’re looking for? As far as Roblox API allows for, this is as close to “changing separate values” as you can get - creating a new Color3 using existing values and changing only the ones you want.

Another way is to hold the colors in variables and work off of those.

local Screen = workspace.screen
local ColorCache = {R = 0, G = 0, B = 0}

-- Pass nil to skip over a change; example function
local function SetColorRGBValues(R, G, B)
    ColorCache.R = R or ColorCache.R
    ColorCache.G = G or ColorCache.G
    ColorCache.B = B or ColorCache.B

    screen.Color = Color3.new(ColorCache.R, ColorCache.G, ColorCache.B)
end

-- In a color adder button
script.Parent.ClickDetector.MouseClick:Connect(function ()
    SetColorRGBValues(255, nil, nil)
end)

-- In a color remover button
script.Parent.ClickDetector.MouseClick:Connect(function ()
    SetColorRGBValues(0, nil, nil)
end)

I wanted a script to be able to do this:

Being able to enable certain colors, to mix them.
It’s useless though…

Wait… I am confused now too… do you want the script to do exactly as in the video?

If so, don’t you already have the script?

If you would spend a few moments actually trying to pick away at a solution, you’d realise it’s not useless. You’re giving up way too soon without trying out solutions or editing them. You also need to understand the concepts that I or any of the other posters are trying to teach you.

My solution works perfectly fine. I’ve even created a Studio repro with relatively the same code as what I just provided in terms of a color cache (which is much easier to work with and readable than my previous solution). The code set up is different by a bit to make it easier to work with, but it works completely fine and achieves exactly the same thing as what the video shows.

RGBColorMixer.rbxl (16.6 KB)

This is obviously only an example and it’ll need to be edited for better usage, but this about achieves what you want and shows the code in practice. Give it a try.

4 Likes

No, I just made a mockup of what I wanted using game.Workspace.part.BrickColor =

THANK YOU SO MUCH.
I’m gonna try and implement this in my game, thank you!