My welding script is not working

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:


local pumpkinHat = game.ReplicatedStorage.Pumpkin


game.Players.PlayerAdded:Connect(function(plr)
	personalPumpkinHat = pumpkinHat:Clone()
	personalPumpkinHat.Parent = game.Workspace
	local weld = Instance.new("Weld")
	weld.Parent = personalPumpkinHat
	weld.Part0 = plr.Character.Head
	weld.C0 = plr.Character.Head.CFrame:Inverse()
	weld.Part1 = personalPumpkinHat
	weld.C1 = personalPumpkinHat.CFrame:Inverse()
	personalPumpkinHat.CFrame = plr.Character.Head.CFrame * CFrame.new(0,3,0)
	
	
	
	
end)

Try to use CharacterAdded event after the PlayerAdded event.

1 Like

Make sure the pumpkin hat is not anchored.

I did that and the game teleported to me for some reason, like imagine if every part in the game teleported to your head.

I would just use a weld constraint.

local part0 = Instance.new("Part")
local part1 = Instance.new("Part")
etc...
part0.CFrame = part1.CFrame * CFrame.new(0,3,0)
local weld = Instance.new("WeldConstraint")
weld.Parent = part0
weld.Part0 = part0
weld.Part1 = part1
1 Like

It still does not seem to be working, no error is in the output too.

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