-- Coded by NYONIC -- a few bugs with setting values I will work out later... you can hide those Gui elements local plr = game.Players.LocalPlayer local plrgui = plr:WaitForChild('PlayerGui') local colorchoice = plr.PlayerGui:WaitForChild("Nyonic'sColorPalette") local mouse = plr:GetMouse() local mousedown = false local colorselector = colorchoice.ColorSelector local newcolor = colorchoice.NewColor -- sets the new color to the NewColor.Value local setting = false -- used as debounce on values being changed by another local lasthex = 'FFFFFF' -- used to set last hex back if not a valid hex format local lastR = 255 local lastG = 255 local lastB = 255 local lastHue = 359 local lastSat = 255 local lastVal = 255 local ROUND_TO = .01 -- studs -- used for Grid System --------------- NEW SYSTEM local function Round(Number) return math.floor((Number / ROUND_TO) + 0.5) * ROUND_TO end local BasePartToSet = colorchoice.BrickToColor.Value or workspace:FindFirstChild('Baseplate') -- this is whatever you want color changed on **************** -- Coded by NYONIC local Color3 = setmetatable({ FromHex = function(int) if string.sub(int,1,1) == '#' then -- removes the html # and replaces with 0x for full hex int = '0x' .. string.sub(int,2,string.len(int)) elseif string.lower(string.sub(int,1,2)) ~= '0x' then -- checks if it has the 0x if not adds it for full hex int = '0x' .. int end return Color3.fromRGB(math.floor(int/256^2)%256,math.floor(int/256)%256,math.floor(int)%256) end, ToHex = function(color) local R = string.format("%02X",color.r * 255) local G = string.format("%02X",color.g * 255) local B = string.format("%02X",color.b * 255) return (R .. G .. B ) -- math.floor(color.r*255)*256^2+math.floor(color.g*255)*256+math.floor(color.b*255) end }, {__index = Color3}) colorselector.MouseButton1Down:Connect(function() mousedown = true colorchoice.Cursor.Visible = true while mousedown do local x = mouse.X local y = mouse.Y local r = colorselector.AbsoluteSize.x/2 -- this gets max radias of color palette and only allows cursor to go to edge even if mouse leaves local d = Vector2.new(x, y) - colorselector.AbsolutePosition - colorselector.AbsoluteSize/2; if (d:Dot(d) > r*r) then d = d.unit * r; end colorchoice.Cursor.Position = UDim2.new(0.5, d.x, 0.5, d.y); x = colorchoice.Cursor.AbsolutePosition.X + colorchoice.Cursor.AbsoluteSize.x/2 y = colorchoice.Cursor.AbsolutePosition.Y + colorchoice.Cursor.AbsoluteSize.y/2 -- gets rotation from location of mouse to center gotten from postion then add half the size local ycenter = (colorselector.AbsolutePosition.Y + colorselector.AbsoluteSize.Y/2) local xcenter = (colorselector.AbsolutePosition.X + colorselector.AbsoluteSize.X/2) local Sat = (Vector2.new(xcenter, ycenter) - Vector2.new(x,y)).Magnitude / (colorselector.AbsoluteSize.X/2) -- gets magnitude from center of image to max size local Hue = math.ceil(math.deg(math.atan2(ycenter - y ,( xcenter - x)))) -- get the roation in degrees from mouse to center of gui image Hue = Hue - 30 -- backs up from the 359 to make it start at red if Hue < 0 then -- if less than 0 a negative between -1 and -179 change it to part of 360 Hue = 359 + Hue end if Sat <= 1 then -- only set while over the wheel colorchoice.Cursor.Position = UDim2.new(0,x,0,y) colorselector.Hue.Text = Hue -- set the hue then the Sat below colorselector.Sat.Text = math.floor(Sat*255) end wait() end end) mouse.Button1Up:Connect(function() mousedown = false end) colorselector.MouseButton1Up:Connect(function( x, y) mousedown = false end) function MoveBrightness(yset) while mousedown do local x = mouse.X local y = mouse.Y if y >= colorselector.BrightnessSelector.AbsolutePosition.Y - 1 and y <= ( colorselector.BrightnessSelector.AbsolutePosition.Y + colorselector.BrightnessSelector.AbsoluteSize.Y) then colorselector.BrightnessSelector.SelectorBar.Position = UDim2.new(0,colorselector.BrightnessSelector.SelectorBar.Position.X, 0,(y- colorselector.BrightnessSelector.AbsolutePosition.Y)) colorselector.Val.Text = math.floor(255*(1-((y - colorselector.BrightnessSelector.AbsolutePosition.Y)/colorselector.BrightnessSelector.AbsoluteSize.Y))) end wait() end if yset then colorselector.BrightnessSelector.SelectorBar.Position = UDim2.new(0,colorselector.BrightnessSelector.SelectorBar.Position.X, 0,colorselector.BrightnessSelector.AbsoluteSize.Y-(yset * colorselector.BrightnessSelector.AbsoluteSize.Y)) end end colorselector.BrightnessSelector.SelectorBar.MouseButton1Down:Connect(function( ) mousedown = true MoveBrightness() end) colorselector.BrightnessSelector.SelectorBar.MouseButton1Up:Connect(function( ) mousedown = false end) colorselector.BrightnessSelector.MouseButton1Down:Connect(function( ) mousedown = true MoveBrightness() end) colorselector.BrightnessSelector.MouseButton1Up:Connect(function( x, y) mousedown = false end) colorselector.Color.MouseButton1Up:Connect(function( x, y) mousedown = false end) -- Coded by NYONIC function SetColor(mode, val) --- HSV, RGB, HEX if setting then return end pcall(function() -- us pcall for error if wrong HEX if mode == 'HSV' then newcolor.Value = Color3.fromHSV(colorselector.Hue.Text/359,colorselector.Sat.Text/255,colorselector.Val.Text/255) elseif mode == 'RGB' then newcolor.Value = Color3.fromRGB(colorselector.R.Text,colorselector.G.Text,colorselector.B.Text) elseif mode == 'HEX' then newcolor.Value = Color3.FromHex(colorselector.Hex.Text) end local H, S, V = Color3.toHSV(newcolor.Value) colorselector.BrightnessSelector.BackgroundColor3 = Color3.fromHSV(H,S,1) -- sets the color as bright as it can be for selector end) end colorchoice.NewColor.Changed:Connect(function() setting = true if not colorselector.R:IsFocused() then colorselector.R.Text = math.floor(newcolor.Value.r * 255) end if not colorselector.G:IsFocused() then colorselector.G.Text = math.floor(newcolor.Value.g * 255) end if not colorselector.B:IsFocused() then colorselector.B.Text = math.floor(newcolor.Value.b * 255) end if not colorselector.Hex:IsFocused() then colorselector.Hex.Text = Color3.ToHex(newcolor.Value) end local H, S, V = Color3.toHSV(newcolor.Value) if not colorselector.Hue:IsFocused() and not colorselector.Sat:IsFocused() then colorselector.Hue.Text = Round(H)*359 colorselector.Sat.Text = Round(S)*255 end if not colorselector.Val:IsFocused() then colorselector.Val.Text = Round(V)*255 end colorselector.Color.ImageColor3 = newcolor.Value if BasePartToSet then -- if there is a BRICK that needs color set BasePartToSet.Color = newcolor.Value end wait() setting = false end) colorselector.Hue.Changed:Connect(function() if colorselector.Hue.Text == '' then colorselector.Hue.Text = 0 return end if not tonumber(colorselector.Hue.Text) then colorselector.Hue.Text = lastHue return end colorselector.Hue.Text = math.clamp(colorselector.Hue.Text,0,359) SetColor('HSV') end) colorselector.Sat.Changed:Connect(function() if colorselector.Sat.Text == '' then colorselector.Sat.Text = 0 return end if not tonumber(colorselector.Sat.Text) then colorselector.Sat.Text = lastSat return end colorselector.Sat.Text = math.clamp(colorselector.Sat.Text,0,255) SetColor('HSV') end) colorselector.Val.Changed:Connect(function() if colorselector.Val.Text == '' then colorselector.Val.Text = 0 return end if not tonumber(colorselector.Val.Text) then colorselector.Val.Text = lastVal return end colorselector.Val.Text = math.clamp(colorselector.Val.Text,0,255) SetColor('HSV') if tonumber(colorselector.Val.Text) and colorselector.Val.Text ~= '' and not mousedown then MoveBrightness(colorselector.Val.Text/255) end end) colorselector.R.Changed:Connect(function() if colorselector.R.Text == '' then colorselector.R.Text = 0 return end if not tonumber(colorselector.R.Text) then colorselector.R.Text = lastR return end colorselector.R.Text = math.clamp(colorselector.R.Text,0,255) SetColor('RGB') end) colorselector.G.Changed:Connect(function() if colorselector.G.Text == '' then colorselector.G.Text = 0 return end if not tonumber(colorselector.G.Text) then colorselector.G.Text = lastG return end colorselector.G.Text = math.clamp(colorselector.G.Text,0,255) SetColor('RGB') end) colorselector.B.Changed:Connect(function() if colorselector.B.Text == '' then colorselector.B.Text = 0 return end if not tonumber(colorselector.B.Text) then colorselector.B.Text = lastB return end colorselector.B.Text = math.clamp(colorselector.B.Text,0,255) SetColor('RGB') end) colorselector.Hex.Changed:Connect(function() colorselector.Hex.Text = string.upper(colorselector.Hex.Text) if colorselector.Hex.Text == '' then return end if #colorselector.Hex.Text > 7 then colorselector.Hex.Text = lasthex -- sets back because not valid return elseif #colorselector.Hex.Text == 7 and string.sub(colorselector.Hex.Text ,1,1) ~= '#' then colorselector.Hex.Text = lasthex -- sets back because not valid return end local int = colorselector.Hex.Text if string.sub(int,1,1) == '#' then -- removes the html # and replaces with 0x for full hex int = '0x' .. string.sub(int,2,string.len(int)) elseif string.lower(string.sub(int,1,2)) ~= '0x' then -- checks if it has the 0x if not adds it for full hex int = '0x' .. int end lasthex = colorselector.Hex.Text -- sets the newest hex incase need to set back later SetColor('HEX') end) -- Coded by NYONIC