Anyone know Color? Need help with this

Hello, I am trying to make a 6 button plus/minus system to change the color of a block by individually changing the RBG values in increments. I got “something” to work but it increments up or down way over than what it’s suppose to and also changes the other values as well. How would I fix this? You can see in the pictures it shows the RBG of the block next to it, after clicking to increase red, it also changes blue?

button = script.Parent.Buttons
part = script.Parent.TestPiece
currentcolor = part.Color
function onClickedRup()
	part.Color = Color3.new(currentcolor.R + .1,currentcolor.G,currentcolor.R)
	wait()
end

function onClickedRdown()
	part.Color = Color3.new(currentcolor.R - .1,currentcolor.G,currentcolor.B)
	wait()
end

function onClickedGup()
	part.Color = Color3.new(currentcolor.R,currentcolor.G + .1,currentcolor.B)
	wait()
end

function onClickedGdown()
	part.Color = Color3.new(currentcolor.R,currentcolor.G - .1,currentcolor.B)
	wait()
end

function onClickedBup()
	part.Color = Color3.new(currentcolor.R,currentcolor.G,currentcolor.B + .1)
	wait()
end

function onClickedBdown()
	part.Color = Color3.new(currentcolor.R,currentcolor.G,currentcolor.B - .1)
	wait()
end

button.RincreaseButton.ClickDetector.MouseClick:connect(onClickedRup)
button.RdecreaseButton.ClickDetector.MouseClick:connect(onClickedRdown)

button.GincreaseButton.ClickDetector.MouseClick:connect(onClickedGup)
button.GdecreaseButton.ClickDetector.MouseClick:connect(onClickedGdown)

button.BincreaseButton.ClickDetector.MouseClick:connect(onClickedBup)
button.BdecreaseButton.ClickDetector.MouseClick:connect(onClickedBdown)

image
image

you’re gonna want color3.fromRGB() color3.new its max value is 1, fromRGBs max value is 255

Color3.new() accepts numbers from 0 to 1 only, not 0 to 255 which is what you want. Use Color3.fromRGB() since this will accept 0 to 255 as it RGB range

1 Like

ur variable currentcolor is only being set at the top, you’d want to re-set the variable after every time you change it
ex:

function onClickedRdown()
	part.Color = Color3.new(currentcolor.R - .1,currentcolor.G,currentcolor.B)
	currentcolor = part.Color
	wait()
end

ur gonna have some other problems after that ones fixed but you’ll figure it out

Tested both.
Not sure if this will help.

Scripting
button = script.Parent.Buttons
part = script.Parent.TestPiece
local inc = 25.5

local function updateColor(rOffset, gOffset, bOffset)
    local color = part.Color
    local r = math.clamp(color.R * 255 + rOffset, 0, 255)
    local g = math.clamp(color.G * 255 + gOffset, 0, 255)
    local b = math.clamp(color.B * 255 + bOffset, 0, 255)
    part.Color = Color3.fromRGB(r, g, b)
end

local buttonMap = {
    RincreaseButton = {inc, 0, 0},
    RdecreaseButton = {-inc, 0, 0},
    GincreaseButton = {0, inc, 0},
    GdecreaseButton = {0, -inc, 0},
    BincreaseButton = {0, 0, inc},
    BdecreaseButton = {0, 0, -inc}
}

for buttonName, offsets in pairs(buttonMap) do
    button[buttonName].ClickDetector.MouseClick:Connect(function()
        updateColor(unpack(offsets))
    end)
end
Scripting
button = script.Parent.Buttons
part = script.Parent.TestPiece

local function updateColor(rOffset, gOffset, bOffset)
	local color = part.Color
	local r = math.clamp(color.R + rOffset, 0, 1)
	local g = math.clamp(color.G + gOffset, 0, 1)
	local b = math.clamp(color.B + bOffset, 0, 1)

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

	print("Red: " .. math.floor(r * 255))
	print("Green: " .. math.floor(g * 255))
	print("Blue: " .. math.floor(b * 255))
end

local buttonMap = {
	RincreaseButton = {0.1, 0, 0},
	RdecreaseButton = {-0.1, 0, 0},
	GincreaseButton = {0, 0.1, 0},
	GdecreaseButton = {0, -0.1, 0},
	BincreaseButton = {0, 0, 0.1},
	BdecreaseButton = {0, 0, -0.1}
}

for buttonName, offsets in pairs(buttonMap) do
	button[buttonName].ClickDetector.MouseClick:Connect(function()
		updateColor(unpack(offsets))
	end)
end
1 Like

It’s definitely worth a shot at trying. I’ll let you know how it goes! Thank you everyone for your answers!

Ah yes. I keep forgetting that, that needs to be updated locally

But I’ve tried fromRGB before and had just about the same result? I’m going to try fixing the currentcolor variable to be local so it updates then I’ll see if there’s a change to using fromRGB

That is just scripting options … just pick out what you like and go with it. Tried to hit a few angles for your consideration.

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