Preventing the death of a player that is welded to an npc while it dies?

characters have the ability to grab onto other humanoids using a weld constraint for a brief time as well as deal damage.

but an annoying issue came up when a humanoid dies.

when one humanoid dies, the other one attached to the dying one also dies:
Capbug.wmv (333.1 KB)

I thought maybe it had to do with the breakjointsondeath property but even with that false for both humanoids the problem still occurs.

why is this happening? if joints are still being broken then how can I truly disable it?

1 Like

This may be to that you might break joints of the attachment attached to the other player

breaking the connection as the player dies might be a bit risky as it would depend on which occurs faster, the weldconstraint breaking or the humanoid dying.

isnt there something a bit more straight-forward?

Show the code that acts for the function that attaches the string to the other player

local module = {}

module.Grab = function(part,grabtime,instantdmg)

local contact = false

local tconnect = part.Touched:Connect(function(hit)

if hit and hit.Parent and part and part.Parent and hit.Parent:FindFirstChild("Humanoid") and part.Parent:FindFirstChild("Humanoid") and

hit.Parent.Humanoid.Health > 0 and part.Parent.Humanoid.Health > 0 and not contact and hit.Parent:IsA("Model") and part.Parent:IsA("Model") then

contact = true

hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - instantdmg

local massmod = require(game.ReplicatedStorage.Mods.Util.CompareModelMass)

local biggestmodel = massmod.Compare(hit.Parent,part.Parent)

if hit.Parent == biggestmodel and part.Parent:FindFirstChild("Humanoid") then

part.Parent.Humanoid.PlatformStand = true

elseif part.Parent == biggestmodel and hit.Parent:FindFirstChild("Humanoid") then

hit.Parent.Humanoid.PlatformStand = true

end

local weld = Instance.new("WeldConstraint")

weld.Parent = part

weld.Part0 = part

weld.Part1 = hit

wait(grabtime)

if weld then

weld:Destroy()

end

if hit.Parent == biggestmodel and part.Parent:FindFirstChild("Humanoid") then

part.Parent.Humanoid.PlatformStand = false

elseif part.Parent == biggestmodel and hit.Parent:FindFirstChild("Humanoid") then

hit.Parent.Humanoid.PlatformStand = false

end

end

end)

wait(1)

if contact == false then

if tconnect then

tconnect:Disconnect()

end

end

end

return module

this is the module for the ability.
during the event of both humanoids dying, the last damage to occur to one humanoid is the instantdmg in this module.
(sorry about the code format I forgot to add the ``` before pasting)

So when the other player dies it needs to detach?

that’s what you suggested right?
the problem I had with that idea tho is that the humanoid could die first before the weld finishes detaching.

But isn’t the weld almost instant at detaching

so is humanoid death.
say for example I setup a humanoid.died event.
when the humanoid dies, this will do something.

I could detach the weld using this method, but because the humanoid died first to fire that event, the weld will still be attached, leading to both humanoids attached to die.

I could check for the hp and see if it is 0, but again, when the humanoid hp is at 0, will the humanoid dying be faster than the if statement checking its hp?

this is why I was asking for something that could prevent this altogether. maybe a way to disable joint breaking completely.

Maybe try to disable the joint rather than destroy it?

wouldnt that be the same speed as destroying?

Try it Im pretty sure not same as destroying

didnt work, the methods used to find out if the humanoid is dead is too slow

What is the hierarchy of your rigs? When I spawn in two animation rigs, hook them together with a WeldConstraint, then kill one, it doesn’t impact the other. Perhaps there are other factors at play?

after doing some checking I noticed some interesting behavior.

the rigs are for custom characters and a player can load one up as their character.

when I connected two rigs that are not a player, they wont die when connected by weldconstraint.
however, if I connect the player with any other rig, both humanoids die.

initially when I looked at the rigs, the custom ones had to be connected with weldconstraints because normal welds wouldnt form.( I think this might be because a humanoid was inside the rig while I was modeling it). but after testing with a normal default rig from the rig spawning plugin, the same results happened regardless.

it has to do with the player somehow and Idk why.

heres the custom character change script:

script

local respawntime = 3
game.Players.CharacterAutoLoads = false
local newcharmod = require(game.ReplicatedStorage.Mods.Util.NewCharacter)


game.Players.PlayerAdded:Connect(function(plr)

--if player dies reload custom char----------------------------
plr.CharacterAdded:Connect(function(char)
if char and char:FindFirstChild("Humanoid") then

char.Humanoid.Died:Connect(function()
local folder = game.ServerScriptService.PlrData:FindFirstChild(char.Name)
if folder then
folder.BeginCreatureRun.Value = nil
folder.Hunger.Value = 100
end
wait(respawntime)
newcharmod.CreateNew(plr,game.ServerStorage.BaseRig,Vector3.new(0,5,0))
end)

end
end)
---------------------------------------------------------------




--setting the model without humanoid death--
newcharmod.CreateNew(plr,game.ServerStorage.BaseRig,Vector3.new(0,5,0))
-----------------------------------------
end)

character spawning module

local module = {}

module.CreateNew = function(plr,newmodel,newpos)
if plr and newmodel then


plr:LoadCharacter()
local bod = newmodel:Clone()

wait()

bod.Parent = game.Workspace
bod.Name = plr.Name

wait()

repeat
wait()
until
bod.Parent == game.Workspace

plr.Character = bod
bod:SetPrimaryPartCFrame(CFrame.new(newpos))
wait()
plr.PlayerGui.UpdateCam:FireClient(plr,bod.Humanoid)


end
end

return module

Not sure if this works, but checkout Humanoid.BreakJointsOnDeath

If that doesn’t work, a workaround would be to use a fake health value. It’s annoying, but it works.

ive tried breakjointsondeath both true and false but it doesnt make a difference.

is there maybe a way to recreate the behavior of a weldconstraint without acually connecting two humanoids?

Can either of the players move while linked? If not, anchoring them should work. I’ve been messing around since you brought up that it’s only a player-related issue, and even using a part as proxy doesn’t help.

Alternatively, you might be able to accomplish the task with a precisely-oriented PrismaticConstraint with length set to the distance between the two parts.

so you were able to reproduce the issue?

Yeah, and nothing seemed to work.