Rope constraint and welding

Hi, I have a script which welds a hat with a rope constraint to a player’s head. When welded, it teleports the player randomly and the rotation is incorrect and random.

Here is the script:

function Weld(weldMe, toThis)
	local weld = Instance.new("Weld")
	weld.Part0 = weldMe
	weld.Part1 = toThis
	weld.C0 = weldMe.CFrame:ToObjectSpace(toThis.CFrame)
	weld.Parent = toThis
end

game.Players.PlayerAdded:Connect(function(plr)
	wait(5) -- the rotation is fine if the character hasn't spawned in, but this waits until it has
	local Model = workspace:FindFirstChild("Buckethat 1")
	local Char = plr.Character or plr.CharacterAdded:wait()
	local Head = Char:WaitForChild("Head")
	
	for i,v in pairs(Model.PrimaryPart:GetChildren()) do
		if v:IsA("Part") then
			Weld(v, Model.PrimaryPart)
			v.Anchored = false
		end
	end
	
	Model.PrimaryPart.Anchored = false
	
	Model:SetPrimaryPartCFrame(CFrame.new(Head.Position.X, Head.Position.Y + .3, Head.Position.Z) * CFrame.Angles(0, math.rad(180), 0))
	Model.Parent = workspace
	Weld(Model.PrimaryPart, Head)
	
	Char.HumanoidRootPart.CFrame = workspace.flowerboyej.HumanoidRootPart.CFrame -- has no effect whatsoever
end)

function Weld(weldMe, toThis)
local weld = Instance.new(“Weld”)
weld.Part0 = weldMe
weld.Part1 = toThis
weld.C0 = weldMe.CFrame:ToObjectSpace(toThis.CFrame)
weld.Parent = toThis
end

game.Players.PlayerAdded:Connect(function(plr)
wait(5) – the rotation is fine if the character hasn’t spawned in, but this waits until it has
local Model = workspace:FindFirstChild(“Buckethat 1”)
local Char = plr.Character or plr.CharacterAdded:wait()
local Head = Char:WaitForChild(“Head”)

for i,v in pairs(Model.PrimaryPart:GetChildren()) do
	if v:IsA("Part") then
		Weld(v, Model.PrimaryPart)
		v.Anchored = false
	end
end

Model.PrimaryPart.Anchored = false

Model:SetPrimaryPartCFrame(CFrame.new(Head.Position.X, Head.Position.Y + .3, Head.Position.Z) * CFrame.Angles(0, math.rad(90), 0))
Model.Parent = workspace
Weld(Model.PrimaryPart, Head)

Char.HumanoidRootPart.CFrame = workspace.flowerboyej.HumanoidRootPart.CFrame -- has no effect whatsoever

end)

trying to change position to see if its correct.