I have been working on creating a pumpkin hat. I want it so that when you join the game it gets attached to your head. I have tried multiple different things and none of them seem to work. One put the part in the correct area but the part did not move with the character. Here is my script:
Hi, firstly, I have two suggestions. You do not need to use CFrame:Inverse() when getting the CFrame of the player’s head. That is likely why the position comes out incorrect when you try to weld the helmet to the player. Secondly, using a WeldConstraint instead of a Weld will make things easier as they’re more flexible than regular welds.
Below is code I wrote to equip a mesh helmet to a player, and it works as intended. I do not use CFrames here but either CFrames or positions will work just fine as long as you account for the LookVector when assigning the helmet’s CFrame.
local Character = game.Players.LocalPlayer.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local CharacterHead = Character:WaitForChild("Head")
local WarriorHelmet = Helmets:WaitForChild("DefaultWarriorHelmet")
local PositionOffset = WarriorHelmet:WaitForChild("PositionOffset").Value
local WarriorHelmetClone = WarriorHelmet:Clone()
local HelmetSlotModel = Instance.new("Model")
HelmetSlotModel.Name = "HelmetSlot"
HumanoidRootPart.Anchored = true
WarriorHelmetClone.Position = CharacterHead.Position
WarriorHelmetClone.Parent = HelmetSlotModel
HelmetSlotModel.Parent = workspace
local weld = Instance.new("WeldConstraint")
weld.Part0 = CharacterHead
weld.Part1 = WarriorHelmetClone
weld.Enabled = true
weld.Parent = WarriorHelmetClone
HelmetSlotModel.Parent = Character
HumanoidRootPart.Anchored = false