So I am making a character/avatar customizer, and I made some of it. I just started and I am getting an error on a script that places the hair. This is the unfinished version of the script(only by a line or 2 which isn't that important). I am very confused on the error. May someone help?
Note:The way it works is that a a remote event fires when an intvalue is changed(by a gui text button). When it changes, it fires a remote event with the only argrument being the value of the intvalue. That value is used to figure out which hair piece will go on the character. Here is my script.(Note: It is a bit long due to the arrays.)
local event = game:GetService('ReplicatedStorage'):WaitForChild('ChangeHair')
local Clothing = {
'None',
'Brown Charmer Hair',
'Black Ponytail',
'Normal Boy Hair',
'Blonde Action Ponytail',
'Stylish Blue Hair',
'Straight Brunette Hair',
'Brooding Black Hair',
'Cinnamon Hair',
'Ravenhaired Charmer',
'Cinnamon Hair',
'Messy Hair',
'Black and Red'
}
local HairIds = {
0,
376548738,
376527350,
13477818,
398673196,
846803597,
3814496544,
13655562,
77799954,
13745548,
26658141,
14815761
}
event.OnServerEvent:Connect(function(fakeplr, value)
print(value)
local insertService = game:GetService('InsertService')
local selectedHair = Clothing[value]
local selectedId = HairIds[value]
if selectedId~= 0 then
local hair = insertService:LoadAsset(selectedId)
hair.Parent = game.Workspace.Rig
end
end)
I will appreciate it if you help as I am very confused.

4 comments
The selectedHair variable will be used in the part of the script that is unfinished.
maybe in firing the server value is nil
The server vakye isn't nil, but for some odd reason, when I try to print selectedId, it doesn't print, so I don't know if that is nil.
Could it be that the arrays are not of even length? So like if the value is 13, you can get the clothing just fine but there are only 12 hair ids so it would get nil on line 40 and probably get the error on line 42. Do a check that selectedId isn't nil right next to the "selectedId~=0"