Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

"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)

3 comments

0

The part your waiting for needs to be inside the parenthesis of WaitForChild()

0

yes the "WaitForChild()" needs an object to wait for in the "()" for example -

0

local RS = game:GetService("ReplicatedStorage") local Function = RS:WaitForChild("Touched")

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.