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

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

Asked by 3 years ago

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 — 3y
0
yes the "WaitForChild()" needs an object to wait for in the "()" for example - bestshot123 38 — 3y
0
local RS = game:GetService("ReplicatedStorage") local Function = RS:WaitForChild("Touched") bestshot123 38 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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
Ad

Answer this question