How to make color picker Gui start on part color

Hi , i’ve been playing around with a color wheel gui and it works, the only problem is that it starts from white so when i edit the color it jumps to white. The color picker converts the position of the picker to hsc values but i want to know how can i take the color from the part and in my script set the position of the picker to that color. I don’t know how i can go in reverse and calculate the position from the color.

here is the script

local colourWheel = script.Parent:WaitForChild(“ColourWheel”)
local wheelPicker = colourWheel:WaitForChild(“Picker”)

local darknessPicker = script.Parent:WaitForChild(“DarknessPicker”)
local darknessSlider = darknessPicker:WaitForChild(“Slider”)

local uis = game:GetService(“UserInputService”)

local buttonDown = false
local movingSlider = false

local player = game.Players.LocalPlayer.UserId
local function updateColour(centreOfWheel)

local car =  workspace:FindFirstChild("Car"..player)

local currentSelection = script.Parent.Parent:WaitForChild("CurrentSelection").Value

local colourPickerCentre = Vector2.new(
	colourWheel.Picker.AbsolutePosition.X + (colourWheel.Picker.AbsoluteSize.X/2),
	colourWheel.Picker.AbsolutePosition.Y + (colourWheel.Picker.AbsoluteSize.Y/2)
)

print("Color picker centre: ")print(colourPickerCentre)




local h = (math.pi - math.atan2(colourPickerCentre.Y - centreOfWheel.Y, colourPickerCentre.X - centreOfWheel.X)) / (math.pi * 2)

local s = (centreOfWheel - colourPickerCentre).Magnitude / (colourWheel.AbsoluteSize.X/2)

local v = math.abs((darknessSlider.AbsolutePosition.Y - darknessPicker.AbsolutePosition.Y) / darknessPicker.AbsoluteSize.Y - 1)


local hsv = Color3.fromHSV(math.clamp(h, 0, 1), math.clamp(s, 0, 1), math.clamp(v, 0, 1))
print(hsv)



if car then 
	car:WaitForChild(currentSelection).Color = hsv
end

darknessPicker.UIGradient.Color = ColorSequence.new{
	ColorSequenceKeypoint.new(0, hsv), 
	ColorSequenceKeypoint.new(1, Color3.new(0, 0, 0))
}

end

colourWheel.MouseButton1Down:Connect(function()
buttonDown = true
end)

darknessPicker.MouseButton1Down:Connect(function()
movingSlider = true
end)

uis.InputEnded:Connect(function(input)

if input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end

buttonDown = false
movingSlider = false

end)

uis.InputChanged:Connect(function(input)

if input.UserInputType ~= Enum.UserInputType.MouseMovement then return end


local mousePos = uis:GetMouseLocation() - Vector2.new(0, game:GetService("GuiService"):GetGuiInset().Y)

--dunny for the literal center
local centreOfWheel = Vector2.new(colourWheel.AbsolutePosition.X + (colourWheel.AbsoluteSize.X/2), colourWheel.AbsolutePosition.Y + (colourWheel.AbsoluteSize.Y/2))

--the distance of the mouse from the cenrer
local distanceFromWheel = (mousePos - centreOfWheel).Magnitude

--task is to first get the color we want, next to convert it to a position on the wheel

local car =  workspace:FindFirstChild("Car"..player)
local currentSelection = script.Parent.Parent:WaitForChild("CurrentSelection").Value
local color = Color3.new()
if car then 
	color = car:WaitForChild(currentSelection).Color 
end


--local temp =  Part.Color -- now how can i calculate the position the picker should be at for that color.
--wheelPicker.Position = 

--updating the position of the wheel picker if we have clicked
if distanceFromWheel <= colourWheel.AbsoluteSize.X/2 and buttonDown then
	
	wheelPicker.Position = UDim2.new(0, mousePos.X - colourWheel.AbsolutePosition.X, 0, mousePos.Y - colourWheel.AbsolutePosition.Y)

	
elseif movingSlider then
	
	darknessSlider.Position = UDim2.new(darknessSlider.Position.X.Scale, 0, 0, 
		math.clamp(
		mousePos.Y - darknessPicker.AbsolutePosition.Y, 
		0, 
		darknessPicker.AbsoluteSize.Y)
	)	
end

print("Center of wheel: ")print(centreOfWheel)
print("picker position ")print(wheelPicker.Position)


updateColour(centreOfWheel)

end)Preformatted text

1 Like

I solved not sure how to delete post sorry

Please message discobot “start tutorial” to know how to do this.

1 Like

He could not post here if he is new. I think he just forgot. Press the “…” and then the trashcan.

You could not post if you have nothing constructive to say