Color Wheel Problem

Recently I slightly remodified a color wheel script to change the lights color, etc. The light changes and everything but it only changes color for the client, (the person who changed the color)
I tried changing the local script into a server script but the color selection does not work.
Here is the Local Script:

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

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

local colourDisplay = game.Workspace.LEDChanger:WaitForChild("PointLight")


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.Color = hsv
	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)

	buttonDown = false
	movingSlider = false
end)


uis.InputChanged:Connect(function(input)


	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)

Any help will be enough, thanks.

You should use Remotes for this.

This way, you send the updated color to the Server and then that in turn will show it for every other Player.
A RemoteEvent would probably be best suited for this.
Also, if it’s a gamepass or a group rank that allows you to change this light color. Remember to check for these requirements on the server, not the client. This eliminates exploiters from abusing it.

1 Like

What part would I have to use a remote event for?

Well, if you change say, a part’s color on your client, the server won’t recognize this. Since it happened on the client, but wasn’t formally relayed to the server.

Test this:
Make a part inside of Workspace called “Brick”

Make a RemoteEvent called “BrickColor” inside of your ReplicatedStorage

Make a LocalScript and put it inside StarterGui with the contents:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local BrickColorEvent = ReplicatedStorage:WaitForChild("BrickColor")

BrickColorEvent:FireServer(BrickColor.new("Bright red"))

Make a Script and put it inside of ServerScriptService with the contents:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")

local BrickColorEvent = ReplicatedStorage:WaitForChild("BrickColor")

BrickColorEvent.OnServerEvent:Connect(function(Player, BrickColor)
	Workspace:WaitForChild("Brick").BrickColor = BrickColor
end)

(this is just a testing example)

I tried this, server script:

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

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

local colourDisplay = game.Workspace.LEDChanger:WaitForChild("PointLight")


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.Color = hsv
	darknessPicker.UIGradient.Color = ColorSequence.new{
		ColorSequenceKeypoint.new(0, hsv), 
		ColorSequenceKeypoint.new(1, Color3.new(0, 0, 0))
	}
end

game.ReplicatedStorage.ColorChange.OnServerEvent:Connect(function(player, centreOfWheel)
	updateColour(centreOfWheel)
end)

Local Script:

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

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

local colourDisplay = game.Workspace.LEDChanger:WaitForChild("PointLight")


local uis = game:GetService("UserInputService")


local buttonDown = false
local movingSlider = false



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

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


uis.InputEnded:Connect(function(input)

	buttonDown = false
	movingSlider = false
end)


uis.InputChanged:Connect(function(input)


	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


	game.ReplicatedStorage.ColorChange:FireServer(centreOfWheel)

end)

The problem with this is now the color wheel stays in one color, it does not want to move colors.

You only add the code that actually changes the color of colourDisplay inside of the OnServerEvent.
image
This needs to be on the client side.

Once the player picks a color, :FireServer the remote and set the color of the colourDisplay to the specified color.

Only thing you want in your .OnServerEvent is colourDisplay.Color = hsv since this actually changes the color to the picked color. So, you :FireServer the remote with the color as one of it’s arguments.