RGB Colour Customization Script for A-Chassis Car doesn't change the car color

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to have a GUI that pops up when you drive your A-Chassis based car through a certain block, in that gui you can use a slider to select a RGB Gradient color and a slider for the saturation of the color, then when pressing a button, it changes your car’s color to the chosen color.

  2. What is the issue? My output shows no errors when preparing the script, or when pressing the button, yet the meshes of the car that are supposed to change colour, do not change. The meshes do not have any textures.

  3. What solutions have you tried so far? I’ve tried to change the way the found meshes change their color depending on the sliders preview colour (but I’m stuck with having a Color3 and a BackgroundColor3) as well as the textboxes for adding the numbers yourself.

wait(.2)

function Click(mouse)
	local plr = script.Parent.Parent.Parent.Parent.Parent
	local plrname = plr.Name
	local carname = plrname.."'s Car"

	for i, carcheck in pairs(game.Workspace:GetChildren()) do
		if carcheck.Name == carname then
			local car = carcheck
			local R = script.Parent.Parent.RGBInput.R.TextBox.Text
			local B = script.Parent.Parent.RGBInput.B.TextBox.Text
			local G = script.Parent.Parent.RGBInput.G.TextBox.Text
			for i, v in pairs(car.Body:GetChildren()) do
				if v.Name == "Colors" then
					for i, part in pairs(v:GetChildren()) do
						if part.Name == "Color" then
							part.Color = Color3.new(R,G,B)
						end
					end

				end
			end
		end
	end
end
script.Parent.MouseButton1Down:connect(Click)

I’m really not the best at scripting, most of the code is taken from different sources and examples.
It does work if I have the colour be a pre defined colour, but I don’t want to have a whole gui full of different coloured buttons, if it can be avoided.

Thank you in advance

1 Like

Are there any errors you got? Or are the other parts of the script working?

I haven’t gotten any errors that I can find. Other parts of the script work, the preview shows the gradient of color you choose by sliding the slider of the RGB Gradient, as well as the saturation.

Here’s extra screenshots:
image

Try doing this but just with brick color

What do you mean “just with brick color”? I’m trying to avoid having loads of buttons for the brick colors.

part.BrickColor = BrickColor.new(1,1,1)

I want it to make the part’s color the same as the one that gets previewed when sliding the slider, not a pre-defined one.

Text changed by a player does not replicate to the server.

Do FromRGB. That’s how you can use the RGB scale.

Along the lines of Color3.FromRGB(R,G,B)

Still doesn’t change the color, no change. Could it be because it’s doing it locally and not through the server?

Yes, doing it on the client can only be seen on the client while doing it on the server is replicated to everyone.

How would I be able to fix this, so that it goes through the server and works? Is this something that would be done by using RemoteEvents?

Yes, fire a remote event on the client and receive it on the server.

I haven’t used RemoteEvents properly, any example or help would be heavily appreciated.

Not a problem. You can read more about it here: Remote Functions and Events

On the client in that local script, you should do the following:

function Click(mouse)
	local plr = script.Parent.Parent.Parent.Parent.Parent
	local plrname = plr.Name
	local carname = plrname.."'s Car"
	local RemoteEvent = game.ReplicatedStorage.RemoteEvent -- create a remote event but name it something else and replace the .RemoteEvent with the new name

	for i, carcheck in pairs(game.Workspace:GetChildren()) do
		if carcheck.Name == carname then
			local car = carcheck
			local R = script.Parent.Parent.RGBInput.R.TextBox.Text
			local B = script.Parent.Parent.RGBInput.B.TextBox.Text
			local G = script.Parent.Parent.RGBInput.G.TextBox.Text
			RemoteEvent:FireServer(R,G,B) -- send the parameters to the server
				end
			end
		end
	end
end

On the server:

local RemoteEvent = game.ReplicatedStorage.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(player, R, G, B)
for i, carcheck in pairs(game.Workspace:GetChildren()) do
		if carcheck.Name == carname then
			local car = carcheck
			for i, v in pairs(car.Body:GetChildren()) do
				if v.Name == "Colors" then
					for i, part in pairs(v:GetChildren()) do
						if part.Name == "Color" then
							part.Color = Color3.FromRGB(R,G,B)
						end
					end

				end
			end
		end

end)

On the server is a Script in ServerScriptStorage correct?

Yes, it does. Regular scripts should be in there.

image
“carname” is undefined, would I need to re-define it?

Yes, forgot to add that in while typing the code.