Basically, I've made a code to randomize skin color, hair, and face. Unfortunately, the hat that spawns doesnt automatically spawn on the player but far away. HOWEVER! The actual hat IS parented inside the character, and when I touch the visible hat, THEN it appears on the players head.
--Hats local InsertService = game:GetService("InsertService") if HatChance == 1 then local Load = InsertService:LoadAsset(TreckyHair) Load.Parent = player.Character elseif HatChance == 2 then local Load = InsertService:LoadAsset(ChestnutStyle) Load.Parent = player.Character.Head elseif HatChance == 3 then local Load = InsertService:LoadAsset(Shaggy) Load.Parent = player.Character.Head elseif HatChance == 4 then local Load = InsertService:LoadAsset(StylishBrownHair) Load.Parent = player.Character.Head elseif HatChance == 5 then local Load = InsertService:LoadAsset(ChestnutSpikes) Load.Parent = player.Character.Head elseif HatChance == 6 then local Load = InsertService:LoadAsset(BlackPigtails) Load.Parent = player.Character.Head elseif HatChance == 7 then local Load = InsertService:LoadAsset(BlondePigtails) Load.Parent = player.Character.Head elseif HatChance == 8 then local Load = InsertService:LoadAsset(Beard1) Load.Parent = player.Character.Head end
How can I make the Hat automatically spawn on the characters head?
When you Load()
assets from InsertService
, a Model
will be returned, and inside that Model
, the asset will be there. That's one of the reasons why it's working -- you're not parenting an accessory, you're parenting a model.
Secondly, you shouldn't be parenting Accessory
objects directly to the head. You should be parenting them simply to the player's Character
, and Roblox will take care of positioning the Accessory
onto the Character
itself accordingly.
Knowing all this, your inserting and parenting should look something like this:
local Load = InsertService:Load(assetId) Load:FindFirstChildOfClass("Accessory").Parent = player.Character