Torso Welding Problem

I have made armor for one of my games. The goal is to make it spawn around the map and if a player touches it, it gets welded to the players torso. I have one issue though. It welds completely wrong.

Code:
local armor = workspace.Armor
local part = script.Parent
local debounce = false
part.Touched:Connect(function(hit)
local torso = hit.Parent:FindFirstChild(“HumanoidRootPart”)
if debounce == false and torso then
debounce = true
local newArmor = armor:Clone()
armor:SetPrimaryPartCFrame(torso.CFrame:ToWorldSpace(CFrame.Angles(0, math.rad(90), 35)))
local weld = Instance.new(“Weld”, torso)
weld.Part0 = torso
weld.Part1 = armor.PrimaryPart
hit.Parent.Humanoid.MaxHealth = hit.Parent.Humanoid.MaxHealth + 100
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.MaxHealth
wait(120)
armor = newArmor
armor.Parent = workspace
debounce = false
end
end)

Any feedback/support would be greatly appreciated!

1 Like

So they way I do it is creating the armor model and insert a fakehead which is invisible representing the player head position :)) I just weld everything to the head, unanchor and weld the fakehead to the head of the player.

In my model, I create a copy of the HumanoidRootPart and weld it to the object.

Then in my script, I weld the HumanoidRootPart of the object to the HumanoidRootPart of the Character!

image

 function Weld(a,b)    
     if b:IsA('BasePart') then
    		local weld = Instance.new('WeldConstraint')
    		weld.Part0 = a
    		weld.Part1 = b
    		--weld.C0 = a.CFrame:inverse()
    		--weld.C1 = b.CFrame:inverse()
    		weld.Parent = a
    	end
    end
    Tank.HumanoidRootPart.CFrame = p.Character.HumanoidRootPart.CFrame
    Weld(Tank.HumanoidRootPart, p.Character.UpperTorso)`

This keeps the rotation of the object retaliative to the character so you don’t have to worry about rotation before welding!

1 Like