0

# "argument 1 missing or nil" what's wrong and how do i fix it?

I'm trying to change the hair color of the character in an easy way using "WaitForChild" I've tried "FindFirstChild" too, but it only works if I put the specific name of that, butit can be any one depending on the choice of the player

(When the player appears, a folder is created on the "head" of the character, depending on the player's choice one of the hairs will go there, I named Hair1, Hair2 and so on, and I try to change the color of that inside the folder)

what's wrong and how do i fix it?

I am a total beginner in scripting

game.ReplicatedStorage.Events.HairColorEvent1.OnServerEvent:Connect(function(plr)
local color = BrickColor.new("Baby blue")

local char = plr.Character

char.Head.Hair:WaitForChild().BrickColor = color   ?------error "argument 1 missing or nil"
end)

0
The part your waiting for needs to be inside the parenthesis of WaitForChild() pickles980 4 — 8d
0
yes the "WaitForChild()" needs an object to wait for in the "()" for example - bestshot123 11 — 8d
0
local RS = game:GetService("ReplicatedStorage") local Function = RS:WaitForChild("Touched") bestshot123 11 — 8d

You are using WaitForChild the wrong way. You don't put the child and then :WaitForChild(), you put it inside. Like this:
char.Head:WaitForChild("Hair").BrickColor = color