Alright, so, I have a problem with welding, when I touch the hat giver it should weld the hat to my head, but it instead welds me below the map and the hat doesn’t go anywhere (That means it is still in the same position) and I have no idea how to fix it.
Script:
local debounce = false
local hat = script.Parent.Parent.Hat
local d = hat:GetChildren()
for i = 1, #d do
if d[i]:IsA("BasePart") then
local newweld = Instance.new("Weld")
newweld.Part0 = hat.PrimaryPart
newweld.Part1 = d[i]
newweld.C0 = hat.PrimaryPart.CFrame:Inverse()
newweld.C1 = d[i].CFrame:Inverse()
newweld.Parent = d[i]
end
end
local function weld(a, b) -- a = CurrentPart, b = Head
local weld = Instance.new("Weld")
weld.Part0 = b
weld.Part1 = a
weld.C0 = b.CFrame:Inverse() * a.CFrame
weld.Parent = hat.PrimaryPart
end
script.Parent.Touched:Connect(function(hit)
if debounce == false then
debounce = true
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
local char = hum.Parent
hat:SetPrimaryPartCFrame(char:WaitForChild("Head").CFrame)
for _, part in pairs(d) do
if part:IsA("BasePart") or part:IsA("MeshPart") or part:IsA("UnionOperation") then
weld(part, char:WaitForChild("Head"))
part.Anchored = false
part.CanCollide = false
end
end
end
end
wait(10)
debounce = false
end)```