Yo guys, so I just did a character customisation system but it’s a really long code and I need help making it shorter. So I got 20 hairstyles and I want to make it every time I click on the arrows GUIs change to the next hairstyle in order of the names/numbers in their names.
and here is how I do it right now, but I think that it’s a bit to long and that we could do something about like looping or something else but I don’t know :
hair.ForwardArrow.MouseButton1Click:Connect(function()
if player.Hair.Value == "Hair1" then
player.Hair.Value = "Hair2"
elseif player.Hair.Value == "Hair2" then
player.Hair.Value = "Hair3"
elseif player.Hair.Value == "Hair3" then
player.Hair.Value = "Hair4"
elseif player.Hair.Value == "Hair4" then
player.Hair.Value = "Hair5"
elseif player.Hair.Value == "Hair5" then
end
end)
If you need more info you can ask me about it on this post I’m really active.
You can store all of the hair values in a table, and store your current index of that table.
local hairValues = {"Hair1","Hair2",...}
local index = 1
hair.ForwardArrow.MouseButton1Click:Connect(function()
if index < #hairValues then
index = index + 1
else
index = 1
end
player.Hair.Value = hairValues[index]
end)
Considering the way you named them in the explorer, I would do it like this
local val = 1
local hairs = game:GetService("ReplicatedStorage").Customisation.Hairs:GetChildren()
function assignHair(val)
player.Hair.Value = "Hair"..tostring(val)
end
assignHair(val)
hair.ForwardArrow.MouseButton1Click:Connect(function()
val = (val + 1) % #hairs
assignHair(val)
end)