Change part color with a simple GUI

the color changer :

  • The scripts

Normal script :

game.ReplicatedStorage.ColorChange.OnServerEvent:Connect(function(plr,Color)
	game.Workspace.Part.Color = Color
end)

Capture
local script1 :

local spp = script.Parent.Parent
script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.ColorChange:FireServer(Color3.fromRGB(spp.Red.Text,spp.Green.Text,spp.Blue.Text))
end)

local script2 :

local spp = script.Parent.Parent
while wait() do
	script.Parent.BackgroundColor3 = Color3.fromRGB(spp.Red.Text,spp.Green.Text,spp.Blue.Text)
end
2 Likes

do you like this color change script ?

its nice but very very simple and preety sure more than half of the people here know how to make it

2 Likes

Ok! Do you want to check math npc

yes and i like it good job on it

1 Like

It’s pretty simple, a better way than the loop, you could use the TextBox.InputChaged event for changing the color on the gui.

If you ever want a challenge, you could add sliders for each value, or even a big circle where you can drag a dot in a color circle and set it to the part.

1 Like

This is a great creation to develop your scripting skill. However, this post is also not in the right category. Instead of Help and Feedback, you could change it to Community Resources. :skull:

Apart from that, I wanted to share with you several beginner flaws and bad practices with your code in hopes that you can put them to good use…

First, you’re using multiple LocalScripts which is completely unnecessary, and the fact that you’re using a loop, and specifically while wait() do is quite a red flag. instead of looping to check for changes, which can take up a bit of performance when used many times, you can listen for changes.

The best and most precise way to do this is with GetPropertyChangedSignal, which is better than the Changed function. Plus, you will be using it for many different things in the future such as cash labels.

Also, you’re not checking if what the player put in the TextBoxes are numbers, which will error if they type anything other than a number.

With this in mind, we can re-write your code into one LocalScript: (parented to ScreenGui)

local replicatedStorage = game:GetService("ReplicatedStorage")

local lastColor = nil
local lastClicked = 0

local function updatePreview()
	pcall(function()
		script.Parent.Color3.BackColor = Color3.fromRGB(
			script.Parent.Red.Text,
			script.Parent.Green.Text,
			script.Parent.Blue.Text
		)
	end)
end

script.Parent.Accept.MouseButton1Click:Connect(function()
	if tick() - lastClicked < 3 then return end -- 3 second cooldown.
	if lastColor == string.format("%i, %i, %i",
		script.Parent.Red.Text, script.Parent.Green.Text, script.Parent.Blue.Text)
	then return end -- Returns end if the color is the same to not over-use the RemoteEvent.
	
	if not replicatedStorage:FindFirstChild("ColorChange")
		or not tonumber(script.Parent.Red.Text)
		or not tonumber(script.Parent.Green.Text)
		or not tonumber(script.Parent.Blue.Text)
	then return end -- Returns end if the RemoteEvent doesn't exist or if any of the text isn't a number.
	
	lastClicked = tick()
	
	lastColor = string.format("%i, %i, %i",
		script.Parent.Red.Text, script.Parent.Green.Text, script.Parent.Blue.Text)

	replicatedStorage.ColorChange:FireServer(
		Color3.fromRGB(
			script.Parent.Red.Text,
			script.Parent.Green.Text,
			script.Parent.Blue.Text
		)
	)
end)

script.Parent.Red:GetPropertyChangedSignal("Text"):Connect(updatePreview)
script.Parent.Green:GetPropertyChangedSignal("Text"):Connect(updatePreview)
script.Parent.Blue:GetPropertyChangedSignal("Text"):Connect(updatePreview)

This kinda looks complex but I added some checks and a cooldown system.

Script in ServerScriptService: (much calmer)

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

replicatedStorage.ColorChange.OnServerEvent:Connect(function(player, color)
	if not color then return end
	_workspace.Part.Color = color
end)

Note: These scripts are untested and improvised. If you plan to use them and encounter an error, try to fix it yourself or reply back for some help.

1 Like

Thank you for telling me this, I am new on scripting [ I think 2 months ] and I am learning a thing everyday