I am creating a Character Creation menu and I’m running into a weird problem with hats and hair.
In my UI you click on a button to choose the NPC’s hair/beard/etc, but for some reason the accessory is not showing up when parented to the NPC via a script.
I can provide code if needed, but it’s a fairly straightforward problem and the code works as intended (parenting the hair to the NPC model in the Viewport) aside from the accessory not displaying for some reason.
I have tried deleting / refreshing the NPC as well, to no avail.
Here you go, I suppose. It’s not much besides what I said.
local function Initialize()
Configuration.Gender.Value = "Male"
Configuration.FirstName.Value = "RAYMOND"
Configuration.LastName.Value = "WESTON"
Configuration.HairColor.Value = Color3.fromRGB(88, 76, 71)
Configuration.SkinColor.Value = Color3.fromRGB(250, 214, 194)
Configuration.HairStyle.Value = hairFolder.Male["Hair-Male-0"]
UpdateHairStyles()
--Initialize Player Preview
if Player and Player.Character then
wait()
else
Player.CharacterAdded:Wait()
end
local Clone = game.ReplicatedStorage.CharacterMenuStorage.TemplateChar:Clone()
Clone.Name = "PlrModel"
Clone.Parent = CharacterViewport
UpdateSkinColor()
SkinColorButtons()
HairStyleButtons()
local CharCam = Instance.new("Camera")
CharCam.Parent = CharacterViewport
CharCam.CFrame = Clone.PrimaryPart.CFrame + Vector3.new(1, 1, -5)
CharCam.CFrame = CFrame.lookAt(CharCam.CFrame.Position, Clone.PrimaryPart.Position)
CharacterViewport.CurrentCamera = CharCam
end
local function UpdateHairStyle()
local Char = CharacterViewport:FindFirstChildOfClass("Model")
for _, hair in ipairs(Char:GetChildren()) do
if hair:IsA("Accessory") and hair.AccessoryType == Enum.AccessoryType.Hair then
hair:Destroy()
end
end
local newHair = Configuration.HairStyle.Value:Clone()
newHair.Handle.Color = Configuration.HairColor.Value
newHair.Parent = Char
end
First code block sets up the viewport and some basic variables. Second code block is specifically what updates the hats.
I can confirm two things:
The NPC in the viewport updates properly. I have a separate function used to change the NPC’s skin tone, which works and updates as intended.
The accessory is properly parented to the NPC model. If I Ctrl+X that model and paste it somewhere else, the NPC displays properly with the accessory. It just doesn’t show or update in the Viewport itself, no matter what I do.
That’s about it. Like I said, nothing special here.
If anyone else comes across this thread, make sure you’ve put your NPC inside of a WorldModel inside of the Viewport, and make sure all your updates occur on the server side, not the client side.