Help making a COLOR WHEEL script MOBILE!

I am making a color wheel system for my game so that players can select custom colors. I just want to know how I would adjust this script so that it works for mobile players too. By the way it works perfectly on PC.

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

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

local colourDisplay = script.Parent:WaitForChild("ColourDisplay")

local uis = game:GetService("UserInputService")


local buttonDown = false
local movingSlider = false


local function updateColour(centreOfWheel)
	
	
	local colourPickerCentre = Vector2.new(
		colourWheel.Picker.AbsolutePosition.X + (colourWheel.Picker.AbsoluteSize.X/2),
		colourWheel.Picker.AbsolutePosition.Y + (colourWheel.Picker.AbsoluteSize.Y/2)
	)
	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))
	
	
	colourDisplay.ImageColor3 = hsv
	darknessPicker.UIGradient.Color = ColorSequence.new{
		ColorSequenceKeypoint.new(0, hsv), 
		ColorSequenceKeypoint.new(1, Color3.new(0, 0, 0))
	}
	script.Parent.SelectedColor.Text = "Color wheel color: ("..math.floor(hsv.R * 255)..","..math.floor(hsv.G * 255)..","..math.floor(hsv.B * 255)..")"
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)
	
	local centreOfWheel = Vector2.new(colourWheel.AbsolutePosition.X + (colourWheel.AbsoluteSize.X/2), colourWheel.AbsolutePosition.Y + (colourWheel.AbsoluteSize.Y/2))
	
	local distanceFromWheel = (mousePos - centreOfWheel).Magnitude
	
	
	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
	
	
	updateColour(centreOfWheel)
end)

Here’s the code to the system. If you have any improvements to suggest or a solution to my problem feel free to tell.

Idk if MouseButton1Down works with touch, but if it doesn’t, i think you can change this

colourWheel.MouseButton1Down:Connect(function()

to this

colourWheel.InputBegan:Connect(function(input)
    if input ~= Enum.UserInputType.MouseButton1 and input.UserInputType ~= Enum.UserInputType.Touch then return end
1 Like


I don’t get it, are you getting the color from every possible combination of colors and trying to match that with the color wheel?

Both, the color wheel has ever type of color including hues and shades and within the color wheel a little selector is here to move around and elect a color of your choice. And on the side there is a shade selector to change the value of the color

Oh color wheel, not color spin wheel…my bad.