Welding code works fine until somebody dies whilst welded - causing future attempts to kill the player

Some Context
In this game I’m allowing VR Users (with big hands) to pick up normal sized player characters. I do this by welding the hand to the character.

The below code is the code for grabbing the player - and it works perfectly!! It allows the VR Person to pick up any player. And I have another script that allows them to drop the player.

The issue arrises if the player dies whilst behind held (beit, reseting or killed by a zombie).
When this happens ANY future player which is attempted to be picked up by this script (and by the same hand) - instantly dies!

Any clues to how I can fix this? I think the issue might be less to do with my script and more to do with how Welds work, which I’ve rarely used so I have no clue what is causing this issue.

Script when a player is picked up:

-- closest = A HumanoidRootPart
-- hand = A part which is controlled by a VR Player
if dist < 3 then -- Checking the magnitude (dist is a magnitude)
	if closest:FindFirstChild('Weld') then -- Checking if the player is already held, if so - destroying the old weld
		closest.Weld.Part1.Weld:Destroy()
		closest.Weld:Destroy()
	end
	local weld = Instance.new('WeldConstraint')
	weld.Part0 = closest
	weld.Part1 = hand
	weld.Parent = closest
	weld.Name = 'Weld'
	
	local ref = Instance.new("ObjectValue")
	ref.Name = 'Weld'
        ref.Value = weld	
	ref.Parent = hand
end

If you need more code, or more info - just ask.

3 Likes

You do not need to make new weld every time. Just change which parts are used in the weld. Also, try a Motor6D. I’m not exactly sure why they die though

1 Like

Even when updating the code to reuse the same weld, the death still occurs

if dist < 3 then
	if closest:FindFirstChild('Weld') then
		closest.Weld.Value.Part1 = nil
		closest.Weld:Destroy()
	end
	if not hand:FindFirstChild('Weld') then
		local weld = Instance.new('WeldConstraint')
		weld.Part0 = hand
		weld.Part1 = closest
		weld.Parent = hand
		weld.Name = 'Weld'
	else
		weld = hand.Weld
		weld.Part1 = closest
	end
	
	local ref = Instance.new("ObjectValue")
	ref.Name = 'Weld'
	ref.Parent = closest
	ref.Value = weld	
end