SOLVED] Making A Text Box Change A Player's Hat Color With RGB Values

Hello,
I am currently making a hat customizer system and was wondering how exactly I could get these rgb values to change the color of a hat? So far I have this:
Local Script:

local p = game:GetService("Players").LocalPlayer
local AccessoryName = script.Parent.Parent.Parent.TextLabel.Text -- making sure its the right accessory
script.Parent.MouseButton1Click:Connect(function()
-- there are 3 text boxes serving as the rgb value changer
	local r = tonumber(script.Parent.Parent.Parent.R.Text)
	local b = tonumber(script.Parent.Parent.Parent.G.Text)
	local g = tonumber(script.Parent.Parent.Parent.B.Text)
	game:GetService("ReplicatedStorage").CustomEvents.Rgb:FireServer(p, AccessoryName, r, g, b)  

end)

Server Script:

game.ReplicatedStorage.CustomEvents.Rgb.OnServerEvent:Connect(function(p, AccessoryName, r, g, b)
	local children = p.Character:GetChildren()
	for i, child in ipairs(children) do
			if child:IsA("Accessory") then
			if child.Name == AccessoryName then
				child.Handle.Color = Color3.fromRGB(r, g, b)
				
			end
			end
		end
	end)

I tried handle.Color, handle.Mesh.Vortexcolor and nothing works, I can’t find any articles on how to achieve this. Does anybody know how I could possibly achieve this?

Update, tried a bunch of things. Still unsure.

from what i remember you cant change the color of a basepart object that have special mesh parented to it
however there is a special basepart where it have meshid property that function exact the same like special mesh but you can change it color

i tried vertex color, regular color, etc and i still cant find any solutions or anything regarding the basepart you speak of.

Actually, you can. The SpecialMesh just has to have no texture. Besides, SpecialMeshes aren’t used in Accessories anymore, at least not by default. Older places might still be using SpecialMeshes.

If you want to change an accessory’s color, you’ll need to set the TextureID property of the corresponding MeshPart to a blank string, and then change the Color property of that MeshPart.

game.ReplicatedStorage.CustomEvents.Rgb.OnServerEvent:Connect(function(p, AccessoryName, r, g, b)
	local children = p.Character:GetChildren()
	for i, child in ipairs(children) do
			if child:IsA("Accessory") then
			if child.Name == AccessoryName then
                local meshPart = child:FindFirstChildOfClass("MeshPart")
                if (meshPart) then
                      meshPart.TextureID = ""
                      meshPart.Color = Color3.fromRGB(r, g, b)
                end
			end
		end
	end)

SpecialMeshes aren’t used in accessories anymore, so don’t worry about checking for them. It’s only MeshParts now, unless R6 is enabled in your place.

Weird. I added a print to the thing, and it’s not printing or changing the color. No errors in output either. This doesn’t make much sense.

You don’t need to sent the player through the remote event, that is automatically done when firing a remote event

On the receiving end the AccessoryName argument would also be the player, r would be the accessory name, etc

1 Like

How would I find the character though if I don’t send the player? I need the player argument to find the character to get the hats.

As I said, the first argument of RemoteEvent.OnServerEvent() is player no matter what

It’s automatically passed through whenever a client does FireServer. This more of a security thing so that someone can’t send a different player through the remote event and thus act like they’re someone else

If I did this on the client

Remote:FireServer(123, true)

On the server I’d get

Remote.OnServerEvent:Connect(function(a, b, c)
    print(a, b, c) -- kingerman88, 123, true
end)
2 Likes

It worked perfectly! Thank you a lot, mr kingerman88

1 Like