How to get inserted accessory to fit on player properly?

I have a script that takes all of the player’s hairs and inserts them into the character. This is so that the player can have their avatar hairs with their custom characters. The problem I’m facing is that the accessories don’t have their proper mesh scaling and offsets. How can I get the accessories to have their respected scale and offset?
20e57b0153583d19d5d037ff264f90d8-png

local IS = game:GetService("InsertService")
local Players = game.Players
local raceFolder = game.ServerStorage.Race
local playersFolder = game.ServerStorage.Players

Players.PlayerAdded:Connect(function(plr)
	local statsFolder = playersFolder:WaitForChild(plr.Name):WaitForChild("Stats")
	
	plr.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		local race = statsFolder:WaitForChild("Race").Value
		if race then
			local humdesc = Players:GetHumanoidDescriptionFromUserId(plr.UserId)
			local hairsStr = humdesc.HairAccessory
			local hairIds = hairsStr:split(",")
			local bodyColor = raceFolder[race]["Body Colors"]:Clone()
			bodyColor.Parent = char
			if hairsStr ~= "" then
				for key, id in pairs(hairIds) do
					local model = IS:LoadAsset(hairIds[key])
					local accessory = model:FindFirstChildWhichIsA("Accessory")
					if accessory then
						local mesh = accessory:FindFirstChild("Mesh", true)
						local specialMesh = accessory:FindFirstChild("SpecialMesh", true)
						if mesh then
							mesh.TextureId = ""
						elseif specialMesh then
							specialMesh.TextureId = ""
						end
						local handle = accessory:FindFirstChild("Handle", true)
						handle.Color = raceFolder[race].HairColor.Value
						hum:AddAccessory(accessory)
					end
					model:Destroy()
				end
			end
		end
	end)
end)
1 Like

Hey there @dompwomp! So what’s going on is that with accessories, you have to be mindful of where the properties are aligned to according to the mesh. So in your case, it looks as if it’s a little bit on the low side so, before attaching it to the humanoid, you’d want to edit its AttachmentPos Y property to fit along the Y Axis properly. Hope this helps!

1 Like

That works to some extent, but doesn’t entirely solve the problem. Most Roblox hairs work with my script, but it’s just the UGC items that mainly don’t. They all have different problems with clipping into the head.
This hair is once again lowered too much.
Capture
This one is lowered too much and too forward
Capture2
I’ve tried comparing them to a normal Robox avatar, but I don’t see a different in their properties.

So your code is using an existing accessory template, cloning it, setting its MeshID, then attaching. As much as I hate to say this, but your best bet is to just pre-insert all the hairs you want to have, adjust each one perfectly, and just attach them. The issue is the script obviously can’t know which hair you are using, and automatically set it’s position. Each hair is different so your method would not work unless you did some crazy math that I don’t even know how to do. Sorry man, I wish I had better news for you. I just don’t think the method you are trying to use is viable. At least not yet it isn’t. You can probably use the content provider and insert the hair directly from the catalog ready to go using the meshID.

1 Like