Help with gamepad operated color wheel

I’m working on a gamepad-operated color wheel and my movements work perfectly, but for some reason, the color wheel doesn’t get the proper color.

Does anyone know a solution?

local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")

local thumbRX, thumbRY, thumbL = 0, 0, 0
local moveRatio = 50
local deadzone = 0.1

local mainFrame = script.Parent
local colorDisplayFrame = mainFrame.Color
local colorWheel = mainFrame.ColorWheel
local colorWheelCursor = colorWheel.Cursor
local valueSelector = mainFrame.ValueSelector
local valueSelectorCursor = valueSelector.Cursor

local function selectNewColor(wheelX, wheelY, barY)
	local hue = math.deg(math.atan2(wheelY - 0.5, wheelX - 0.5)) + 180
	local saturation = math.sqrt((wheelX - 0.5)^2 + (wheelY - 0.5)^2) * 2

	local value = 1 - barY
	value = math.clamp(value, 0, 1)

	local color = Color3.fromHSV(hue, saturation, value)
	colorDisplayFrame.BackgroundColor3 = color
	valueSelector.UIGradient.Color = ColorSequence.new(Color3.fromHSV(hue, saturation, 0), Color3.fromHSV(hue, saturation, 1))
end

UIS.InputChanged:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Thumbstick2 then
		thumbRX = math.abs(input.Position.X) > deadzone and input.Position.X or 0
		thumbRY = math.abs(input.Position.Y) > deadzone and input.Position.Y or 0
	elseif input.KeyCode == Enum.KeyCode.Thumbstick1 then
		thumbL = math.abs(input.Position.Y) > deadzone and input.Position.Y or 0
	end
end)

RS.RenderStepped:Connect(function()
	if mainFrame.Visible then
		local wheelCursorPosition = colorWheelCursor.Position
		local barCursorPosition = valueSelectorCursor.Position
		local centerX, centerY = 0.5, 0.5
		local radius = 0.5

		local newWheelX = wheelCursorPosition.X.Scale + (thumbRX / moveRatio)
		local newWheelY = wheelCursorPosition.Y.Scale - (thumbRY / moveRatio)
		local newBarY = math.clamp(barCursorPosition.Y.Scale + (-thumbL / moveRatio), 0, 1)

		local distance = math.sqrt((newWheelX - centerX) ^ 2 + (newWheelY - centerY) ^ 2)

		if distance > radius then
			local angle = math.atan2(newWheelY - centerY, newWheelX - centerX)
			newWheelX = centerX + radius * math.cos(angle)
			newWheelY = centerY + radius * math.sin(angle)
		end

		colorWheelCursor.Position = UDim2.fromScale(newWheelX, newWheelY)
		valueSelectorCursor.Position = UDim2.fromScale(0, newBarY)

		selectNewColor(newWheelX, newWheelY, newBarY)
	else
		colorWheelCursor.Position = UDim2.fromScale(0.5, 0.5)
		valueSelectorCursor.Position = UDim2.fromScale(0, 0)
	end
end)