i have made a script that involves selecting a colour from a colour wheel and it becomes the same colour onto a certain part/mesh, however the problem i am having is its not coming out as the right colour, e.g. blue is white etc
1 Like
Can you post your script so I can see what the issue could be
2 Likes
Theres nothing we can help with unless you paste the script into the post
1 Like
As others pointed out, please provide more details so that we can properly help you.
1 Like
sorry, heres the script:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local TweenService = game:GetService("TweenService")
-- Reference the ScreenGui (ColorPickerGui)
local colorGui = script.Parent
colorGui.Enabled = false -- Start hidden
-- Frame and UI elements
local frame = colorGui:WaitForChild("Frame")
local colorWheel = frame:WaitForChild("ImageButton") -- Color Wheel
local colorPreview = frame:FindFirstChild("ColorPreview")
local colorTextBox = frame:FindFirstChild("ColorTextBox") -- TextBox for RGB input
local confirmButton = frame:FindFirstChild("ConfirmButton") -- Confirm Button
local cancelButton = frame:FindFirstChild("CancelButton") -- Cancel Button
-- Ensure UI elements start fully invisible
colorWheel.ImageTransparency = 1
confirmButton.BackgroundTransparency = 1
cancelButton.BackgroundTransparency = 1
confirmButton.TextTransparency = 1
cancelButton.TextTransparency = 1
local selectedColor = Color3.new(1, 1, 1) -- Default white
local originalColor = nil -- Store original color
local selectedPartName = nil -- Track selected part
-- Function to fade in UI elements
local function fadeInUI()
colorGui.Enabled = true
-- Create Tween Info
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
-- Tween for color wheel
local colorWheelTween = TweenService:Create(colorWheel, tweenInfo, {ImageTransparency = 0})
colorWheelTween:Play()
-- Tween for Confirm button
local confirmTween = TweenService:Create(confirmButton, tweenInfo, {
BackgroundTransparency = 0.8,
TextTransparency = 0
})
confirmTween:Play()
-- Tween for Cancel button
local cancelTween = TweenService:Create(cancelButton, tweenInfo, {
BackgroundTransparency = 0.8,
TextTransparency = 0
})
cancelTween:Play()
end
-- Function to fade out UI elements (when closing)
local function fadeOutUI()
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
local colorWheelTween = TweenService:Create(colorWheel, tweenInfo, {ImageTransparency = 1})
colorWheelTween:Play()
local confirmTween = TweenService:Create(confirmButton, tweenInfo, {
BackgroundTransparency = 1,
TextTransparency = 1
})
confirmTween:Play()
local cancelTween = TweenService:Create(cancelButton, tweenInfo, {
BackgroundTransparency = 1,
TextTransparency = 1
})
cancelTween:Play()
task.delay(0.5, function()
colorGui.Enabled = false
end)
end
-- Detect when a gun part is clicked
mouse.Button1Down:Connect(function()
local target = mouse.Target
if target and target:IsDescendantOf(workspace:FindFirstChild("Gun")) then
selectedPartName = target.Name
colorGui:SetAttribute("SelectedPartName", selectedPartName)
originalColor = target.Color -- Store original color
selectedColor = originalColor
-- Convert current color to RGB (0-255 format)
local r = math.floor(selectedColor.R * 255)
local g = math.floor(selectedColor.G * 255)
local b = math.floor(selectedColor.B * 255)
-- Update UI elements
if colorPreview then
colorPreview.BackgroundColor3 = selectedColor
end
if colorTextBox then
colorTextBox.Text = string.format("%d, %d, %d", r, g, b)
end
fadeInUI()
end
end)
-- Function to convert text input into Color3
local function updateColorFromText()
if colorTextBox and colorTextBox.Text then
local r, g, b = string.match(colorTextBox.Text, "(%d+),%s*(%d+),%s*(%d+)")
if r and g and b then
r, g, b = tonumber(r), tonumber(g), tonumber(b)
if r and g and b then
selectedColor = Color3.fromRGB(r, g, b)
if colorPreview then
colorPreview.BackgroundColor3 = selectedColor
end
-- Apply color immediately to the selected part
if selectedPartName then
local gunModel = workspace:FindFirstChild("Gun")
if gunModel then
local gunPart = gunModel:FindFirstChild(selectedPartName)
if gunPart then
gunPart.Color = selectedColor
end
end
end
end
end
end
end
-- Update color from text box input
colorTextBox.FocusLost:Connect(updateColorFromText)
-- When clicking the color wheel, preview the color and apply immediately
colorWheel.MouseButton1Down:Connect(function()
-- Get the position of the mouse relative to the screen
local clickPos = Vector2.new(
mouse.X - colorWheel.AbsolutePosition.X,
mouse.Y - colorWheel.AbsolutePosition.Y
)
-- Make sure the position is within the bounds of the color wheel image
if clickPos.X < 0 or clickPos.X > colorWheel.AbsoluteSize.X or clickPos.Y < 0 or clickPos.Y > colorWheel.AbsoluteSize.Y then
return -- If outside bounds, do nothing
end
-- Normalize the click position
local wheelSize = colorWheel.AbsoluteSize
local normalizedX = clickPos.X / wheelSize.X -- This controls the Hue (horizontal axis)
local normalizedY = clickPos.Y / wheelSize.Y -- This controls the Saturation (vertical axis)
-- Adjust to map the hue to 0-1 range and saturation to 0-1 range
local hue = normalizedX
local saturation = math.min(normalizedY, 1) -- Ensure saturation doesn't exceed 1
local value = 1 -- Max brightness
-- Check if the position is near the center (white color zone)
local centerDistance = (clickPos - Vector2.new(wheelSize.X / 2, wheelSize.Y / 2)).Magnitude
local maxRadius = math.min(wheelSize.X, wheelSize.Y) / 2
if centerDistance < maxRadius * 0.1 then -- Inside the central area, treat as white
saturation = 0
hue = 0 -- Hue is irrelevant for white
value = 1 -- White is always fully bright
end
-- Convert the normalized HSV to RGB
selectedColor = Color3.fromHSV(hue, saturation, value)
-- Update the preview and RGB text box
if colorPreview then
colorPreview.BackgroundColor3 = selectedColor
end
-- Convert to RGB (0-255 format)
local r = math.floor(selectedColor.R * 255)
local g = math.floor(selectedColor.G * 255)
local b = math.floor(selectedColor.B * 255)
-- Update the RGB textbox
if colorTextBox then
colorTextBox.Text = string.format("%d, %d, %d", r, g, b)
end
-- Apply color immediately to the selected part
if selectedPartName then
local gunModel = workspace:FindFirstChild("Gun")
if gunModel then
local gunPart = gunModel:FindFirstChild(selectedPartName)
if gunPart then
gunPart.Color = selectedColor
end
end
end
end)
-- When "Confirm" button is clicked, close the GUI
confirmButton.MouseButton1Click:Connect(fadeOutUI)
-- When "Cancel" button is clicked, revert color and close the GUI
cancelButton.MouseButton1Click:Connect(function()
if selectedPartName then
local gunModel = workspace:FindFirstChild("Gun")
if gunModel then
local gunPart = gunModel:FindFirstChild(selectedPartName)
if gunPart then
gunPart.Color = originalColor -- Revert to original color
end
end
end
fadeOutUI()
end)
1 Like
Do they all come out as separate colour or do they all come out white?
separate, if you need me to i can provide some screenshots of it