I’m trying to get a head to change to the player’s Body Colors.HeadColor via BrickColor, and if bodyColors isn’t found, then pick a random skin tone from the table. I’ve made sure BodyColors is a member of the character, but it still generates a random skin tone from the table.
...
if bodyColors then
astroHead.BrickColor = BrickColor[bodyColors.HeadColor]
else
...
And bodyColors is defined at the top of the script
local bodyColors = Character:FindFirstChild("Body Colors", true)
Bigger picture (not the whole script obviously)
local bodyColors = Character:FindFirstChild("Body Colors", true)
local realisticSkinTones = {
Color3.fromRGB(86, 66, 54),
Color3.fromRGB(204, 142, 105),
Color3.fromRGB(53, 40, 33),
Color3.fromRGB(171, 118, 88)
}
...
if bodyColors then
astroHead.BrickColor = BrickColor[bodyColors.HeadColor]
else
astroHead.Color = realisticSkinTones[math.random(1, #realisticSkinTones)]
end
No errors are being returned, although I did used to recieve attempt to index nil with HeadColor, until I changed local bodyColors = player:FindFirstChild("Body Colors", true) to local bodyColors = Character:FindFirstChild("Body Colors", true)
The target object is a head, with a humanoid sibling-ed to it, yes.
No, HeadColor is a BrickColor type. It is not a string. I assure you that it’s precisely the type you want.
I’ve tested this script in studio and it works as I’d expect:
local colorChangingPart = workspace.ColorPart
local pl = game:GetService("Players").LocalPlayer
local ch = pl.Character or pl.CharacterAdded:Wait()
local bodyColors = ch:WaitForChild("Body Colors")
colorChangingPart.BrickColor = bodyColors.HeadColor
If this still isn’t working for you, you need to add some print statements and tell us the output. I’m not sure how to help at this point based on the info I have. Maybe it’d be better to provide the full script.