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

Accessing Color3.h, Color3.s, and Color3.v?

I'm trying to make color sliders for my game. Originally, I was using RGB values, and everything was fine. However, I decided that HSV sliders might be better. So, when I changed all of the "Color3.new" to "Color3.fromHSV", it no longer worked, technically. The color value always output as (0, 0, 0). I believe this is because, while I can access Color3.r, g, and b, I can't access Color3.h, s, and v. This is a problem, because I only want to change one property at a time; one property is a variable, and the rest I would hypothetically want to use ImageColor3.s, or ImageColor3.v. How could I do something like this?

Here's the code, if it helps. Around line 28 is the problem in question. It works just fine if I switch Color3.fromHSV to Color3.new.

local UIS = game:GetService("UserInputService")
local RuS = game:GetService("RunService")
local slider = script.Parent.Slider
local bar = script.Parent
local held = false
local customcolor = script.Parent.Parent.CustomColor

function snap(number, factor)
	if factor == 0 then
		return number
	else
		return math.floor(number/factor+0.5)*factor
	end
end

UIS.InputEnded:connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		held = false
	end
end)

script.Parent.MouseButton1Down:connect(function()
	held = true
end)

RuS.RenderStepped:connect(function(delta)
	if held then
		script.Parent.Parent.CustomColor.ImageColor3 = Color3.fromHSV(slider.Position.X.Scale, customcolor.ImageColor3.G, customcolor.ImageColor3.B)
		local MousePos = UIS:GetMouseLocation().X
		local pos = snap((MousePos-bar.AbsolutePosition.X)/bar.AbsoluteSize.X,0.02)
		local percentage = math.clamp(pos,0,1)
		slider.Position = UDim2.new(percentage,0,slider.Position.Y.Scale, slider.Position.Y.Offset)
		wait()
	end
end)

3 comments

0

S isn't Green, V isn't Blue

0

bump

0

Yeah, but S and V aren't real properties I can use.

1 answer

This is what you need to convert your RGB into HSV. You need to convert RGB into HSV first and then HSV to RGB again since Color3 is Mainly RGB in the first place xD. I mean it's really necessary to have HSV if you have RGB color picker.

script.Parent.Parent.CustomColor.ImageColor3 = Color3.fromHSV(Color3.toHSV(customcolor.ImageColor3.R, customcolor.ImageColor3.G, customcolor.ImageColor3.B))

If you want to go for HSV color picker Image :) Have fun

2 comments

0

Thank you for responding! I'm confused, though. Putting this code results in an error that says "bad argument #1 to 'toHSV' (Color3 expected, got number)". It works fine if I simply put "Color3.toHSV(customcolor.ImageColor3", but then I'd still be unsure how to pull HSV values from it. It still even says it's a number value, and not a Color3 value, so I cant even pull R, G, or B. What should I do?

0

Oh yes, I forgot creating a New Color3 Value xD, toHSV(customcolor.ImageColor3) is better than to(Color3.new(customcolor.ImageColor3.R,customcolor.ImageColor3.G,customcolor.ImageColor3.B)) :> , unless you're forming the color from different parts

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