Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I get an error, argrument 1 missing or nil, please help?

Asked by 4 years ago
Edited 4 years ago

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.

0
The selectedHair variable will be used in the part of the script that is unfinished. didyoujustoofed 7 — 4y
0
maybe in firing the server value is nil HappyTimIsHim 652 — 4y
0
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. didyoujustoofed 7 — 4y
0
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" CeramicTile 847 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Solution A

Your arrays are not the same length, and value is likely nil. You have to pass a valid argument to value from the client in order to make it work. If you're passing something that cannot be replicated over the server/client boundary, that could also be why it's nil.

As for the arrays, I suggest that you make them the same length. #Clothing is 13 and #HairIds is 12. Go through the first array and insert another ID into HairIds according to the values in Clothing.

Solution B

When you insert an accessory using the InsertService, it will always be parented to a model. If you parent the model itself to the rig, the accessory will not be attached to the rig. Therefore, line 43 is incorrect.

Line 43 should actually be:

hair:FindFirstChildWhichIsA("Accessory").Parent = workspace.Rig
hair:Destroy()

Please note that the code is not supposed to be fully functional. If the hair is not an accessory (because I haven't developed in a while), then replace Accessory with the hair's ClassName.

0
Thank you, you explained the solution well. ;) didyoujustoofed 7 — 4y
Ad
Log in to vote
1
Answered by
Robin5D 186
4 years ago
Edited 4 years ago

Try this:

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'
} -- do the same thing here, do [id] = 'None' or the specific clothing


local HairIds = {
    [0] = false,
    [376548738] = true,
    [376527350] = true,
    [13477818] = true,
    [398673196] = true,
    [846803597] = true,
    [3814496544] = true,
    [13655562] = true,
    [77799954] = true,
    [13745548] = true,
    [26658141] = true,
    [14815761] = true
}


event.OnServerEvent:Connect(function(fakeplr, value)
    print(value)
    local insertService = game:GetService('InsertService')
    local selectedHair = Clothing[value]
    local selectedId = HairIds[value]
    if selectedId then
        local hair = insertService:LoadAsset(value)
        hair.Parent = game.Workspace.Rig
    end
end)

Answer this question