I've designed a script to change the color of hair that I've set up in a morph room. It works fine in all but, the script for the color swap is getting packed(Almost 1000 lines) and theres a delay. I feel that there has to be a more efficient way to doing this.
This is a part of the script for one of the hairs.
-------Long Hair-------
local longhairs = hats["Long Hair"]
local longhair = longhairs["Long Hair"].Handle.Mesh
--Color
local longhair1 = longhairs["1"].ColorPicker
local longhair2 = longhairs["2"].ColorPicker
local longhair3 = longhairs["3"].ColorPicker
local longhair4 = longhairs["4"].ColorPicker
local longhair5 = longhairs["5"].ColorPicker
local longhair6 = longhairs["6"].ColorPicker
local longhair7 = longhairs["7"].ColorPicker
local longhair8 = longhairs["8"].ColorPicker
--1
longhair1.MouseClick:Connect(function(player)
longhair.VertexColor = Vector3.new(1, 1, 1)
end)
--2
longhair2.MouseClick:Connect(function(player)
longhair.VertexColor = Vector3.new(0.7, 0, 1)
end)
--3
longhair3.MouseClick:Connect(function(player)
longhair.VertexColor = Vector3.new(0.68, 0.484, 0.275)
end)
--4
longhair4.MouseClick:Connect(function(player)
longhair.VertexColor = Vector3.new(0.4, 0.292, 0.236)
end)
--5
longhair5.MouseClick:Connect(function(player)
longhair.VertexColor = Vector3.new(0.185, 0.183, 0.184)
end)
--6
longhair6.MouseClick:Connect(function(player)
longhair.VertexColor = Vector3.new(1, 0.941, 0.705)
end)
--7
longhair7.MouseClick:Connect(function(player)
longhair.VertexColor = Vector3.new(0.375, 0.128, 0.112)
end)
--8
longhair8.MouseClick:Connect(function(player)
longhair.VertexColor = Vector3.new(1, 0.7, 1)
end)
Theres a bunch of buttons that these are connected to that swap out the color. Is there a way to shorten this code to check what button is being pressed and for what color to be used?

4 comments
try using a numeric for loop
How would I do that?
some thing like for i=1, #longhairs:GetChildren() do end
I'll check that out.