Attempt to index function with 'WaitForChild'

Hi! I’m trying to make a character creator and I’ve ran into an issue.

When the code runs and I press the other skin colors button, I run into the error in the title.

Here’s the bit of code that causes errors:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local storage = game:GetService("ReplicatedStorage"):WaitForChild("CharacterCreator")
local skin = storage:WaitForChild("Skin")
local skinFrame = script.Parent.Skin

local skinColorList = {
	[1] = "White",
	[2] = "Asian",
	[3] = "Dark",
	[4] = "Black"
}

local function skin()
	local currentIndex = table.find(skinColorList, skinFrame.Selected.Text)
	if currentIndex == 4 then
		skinFrame.Selected.Text = jobList[1]
	else
		skinFrame.Selected.Text = jobList[currentIndex + 1]
	end
	local newColor = skin:WaitForChild(skinFrame.Selected.Text)
         --The error happens on the line above
	plr.BodyColors:Destroy()
	newColor:Clone().Parent = char
end

My UI is set up like below, where skinFrame is “Skin” and Handler is my script
image

I’ve looked up the error on the internet and on the Devforum but I couldn’t find anything useful.

Help is greatly appreciated! :smile:

1 Like

This is because the script thinks you’re trying to run the function skin() instead of indexing the variable. Try changing the name of the function.

1 Like

This is due to variable overshadowing, you have two variables with the same name defined in a single scope [skin]. So when you try to call skin:WaitForChild, it wrongly references the function instead of the variable.

1 Like

Oh, yeah didn’t even notice, haha! Thanks for the help everyone!

1 Like