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

Trying to change all body colors to the same color as the head?

I'm trying to change all of the player's body colors to the same color of the player's head. I currently have a table containing the different colors of the class "BodyColors", and I'm attemtping to go through the table and set that specific color to that of the head, in the "BodyColors" class. However when I run the program, I get this error:

Workspace.ExcelUp.ChangeBodyColors:5: attempt to index a nil value

The script is located in the "StarterCharacterScripts" of the "StarterPlayer". Please can somebody help me?

Character = script.Parent
BodyColors = {"HeadColor", "LeftArmColor", "LeftLegColor", "RightArmColor", "RightLegColor", "TorsoColor"}

for _,Color in pairs(BodyColors) do
	Character:FindFirstChild("Body Colors")[Color] = Character:FindFirstChild("Body Colors")["HeadColor"]
end

1 answer

✓ Accepted answer

Your code is running before BodyColors finishes loading. There's an event on LocalPlayer that'll tell you when the appearance is loaded, alternatively you can just add: character:WaitForChild("Body Colors") on line 3. Provided you're not doing anything else with the script it won't matter if the script hangs.

1 comment

0

Thank you. Much appreciated. I guess I'll work some more on using FindFirstChild and WaitForChild in the correct instances, to prevent this problem occuring again in the future. Again, thank you.

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