Adding Hair Accessory to Character Scaling Issue

In my game I have a customization system (in this system, players can customize their hairs). For my system, I am using Humanoid:AddAccessory, to create a new hair accessory for the player to wear. However, the problem I am having is that the hair accessory is not scaling correctly, and in the screenshot below, you can see that the hair takes up over half the face.
image

I have tried changing the scale values on the mesh, the size of the handle under the accessory, and the positions, but I have not come to a solution. I am looking for any idea on how I can make these hair accessories scaled and properly fitted to the character. Below is the code that handles the hair accessory creation.

hair.Name = "Hair"
 
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Size = Vector3.new(1,1,1)
handle.Parent = hair
handle.BrickColor = BrickColor.Random()
				
 
local HairAttachment = Instance.new("Attachment")
HairAttachment.Name = "HairAttachment"
HairAttachment.Position = Character.Head.HairAttachment.Position
HairAttachment.Parent = handle
handle.Position = HairAttachment.Position
 				
local mesh = Instance.new("SpecialMesh")
mesh.Name = "Mesh"
mesh.Scale = Vector3.new(1,1.3,1)
mesh.MeshId = v.ImageLabel.Image
mesh.Parent = handle
				
local weld = Instance.new("Weld")
weld.Name = "weld"
weld.Parent = handle
weld.Part0,weld.Part1 = handle,Character.Head
				
humanoid:AddAccessory(hair)

I appreciate any help, thanks :smiley:

2 Likes

I wonder why you’d use two parts instead of one. You could manually adjust the accessory and store it, then clone and add it to the character instead.

local accessory = game:GetService("ServerStorage").Accessory
humanoid:AddAccessory(accessory:Clone()) -- don't know if it works

Or if you insist on using pure code only. Try adjusting the HairAttachment.Position's Y axis, by adding + Vector3.new(0,Y,0). Trial and error for the “perfect” fit.

Don’t worry about adding it to the character, the accessory will automatically reposition in relative to the attachments.

I have tried your suggesstion, and even after adding a y value to the HairAttachment.Position, in this case I did
HairAttachment.Position + Vector3.new(0,10,0),
and no change occured. As you can see in the screenshot, the hairattachment did in fact move up, but the hair accessory itself did not change at all.

image

Also, even if this did work, wouldn’t it vary per hair and per body type of the character? Is there any kind of universal method that scales and positions the accessory to fit on any kind of character?

Pretty sure there is none, because the meshes’ sizes always wound up being irregular and the center of the mesh is always shifted. Manual way should do the trick first.

I’m super confused about why the attachment moved up but not the hair.

(Oh looks like I was tired last time, it was one single part.)

I tried the other method you suggested by storing them and calling upon them, however, still getting the same issue with the HairAttachment not changing the accessories position when I change the y value for HairAttachment. I also tried changing the y position of the handle as well, and no change.

Another issue related to this is that some items come scaled out crazy. For example in this image, this witches hat is extremely large, meanwhile another item using the same mesh scaling will come out a completely different size and nothing is scaling to the character.
image

How do these top games such as Royale High or MeepCity make the items in their massive shops scale to players? I’m quite confused on how they accomplish this.

I personally stopped using SpecialMesh since the advent of MeshPart. Not only does it allow you to add materials to existing meshes unlike SpecialMesh, but you can treat the mesh and the part as one instance. Never had an issue with hat rescaling since, because changing the MeshPart’s size also means changing the mesh size. It doesn’t rely on a separate instance.

Another point is that I don’t arbitrarily create accessories. I always keep them stored in a storage service if I know exactly what I want and then I work from there. I’m not a fan of arbitrary creation so I always try and hardcode where possible. Probably not a good habit but gets rid of weird issues the best.

2 Likes