HumanoidRootPart weld killing both players

I just realized that humanoid damaging himself is not a real problem. The problem is HumanoidRootPart weld. I want to make a Kamehameha that pushes back the target, but both the target and attacker die when trying to weld the target’s HumanoidRootPart or Torso to BlastPart2, which is the end of the energy wave.

local function onHitboxTouched(otherPart)
	local otherCharacter = otherPart.Parent
	local otherHumanoid = otherCharacter:FindFirstChild("Humanoid")
	local otherHumanoidRootPart = otherCharacter:FindFirstChild("HumanoidRootPart")
	local chargedKi = charge.Value/90
	local damage = 10 + 90 * chargedKi
	if otherHumanoid and otherHumanoid ~= humanoid and otherHumanoidRootPart then
--		local rootWeld = Instance.new("Weld")
--		rootWeld.Name = "RootWeld"
--		rootWeld.Part0 = blastPart2
--		rootWeld.Part1 = otherHumanoidRootPart
--		rootWeld.Parent = blastPart2
		hitboxPart:Destroy()
		delay(0, function()
			repeat wait() until blastPart2.Transparency < 1
			otherHumanoid:TakeDamage(damage)
		end)
	end
end
hitboxPart.Touched:Connect(onHitboxTouched)

The commented section is what’s going on. When I weld the HumanoidRootPart of a player to a part who belongs to another player, both players die. How can I do this without killing both players?

RBXL File for Debugging.rbxl (29.0 KB)

3 Likes

First off, I’ll start by saying you should consider making some animations with the Animation Editor, rather than using all that Weld modification stuff.

After that, try putting a “if otherHumanoid == humanoid then return end” in the damage function. This will stop the rest from running if the humanoid it hits is the same as the player’s humanoid.

2 Likes

Try comparing the Humanoid’s parents

2 Likes

The logic of the script seems to be fine, for debugging, try adding this right before the if then:

print(humanoid:GetFullName(), otherHumanoid:GetFullName())

This would help in verifying that you indeed have the right humanoids. If possible, provide a .rbxl file for the place so we can test the same as well.


On another note, please use #development-support:scripting-support for help, this category is not apt for it.

2 Likes

If you keep on hitting yourself, then maybe try a if Hit:IsADescendentOf function. This’ll see if the Wave came from a player, if it did, then it would avoid being hit. Hope this helps!

— Drinkinix :smiley:

3 Likes

@BanCredit, the debugging you recommended me shows this:
Workspace.Player1.Humanoid Workspace.Player2.Humanoid

Which suggests it’s differentiating your humanoid from the other humanoid correctly. I tried doing what @Zeezy666 and @plasmascreen suggested, but nothing changed at all. The enemy keeps countering the energy wave and damaging the attacker no matter how many checks I do for some reason. I’ve edited the post with what you guys suggested and added the .rbxl file.

@Drinkinix, can you be more specific? I never worked with that instance, and an example would be helpful.

1 Like

For example. Here’s a script I made a while back.

local AlreadyDamaged = {}
        MainShockwave.Touched:Connect(function(Hit)
            if not Hit:IsDescendantOf(Character) and Hit.Parent:FindFirstChild('Humanoid') then
                local Humanoid = Hit.Parent.Humanoid
                
                if AlreadyDamaged[Humanoid] ~= true then
                    
                    AlreadyDamaged[Humanoid] = true
                    Humanoid:TakeDamage(Damage) -- Add formula for level + stats
                    local BV = Instance.new("BodyVelocity")
                    BV.MaxForce = Vector3.new(100000,100000,100000)
                    BV.Velocity = MainShockwave.CFrame.lookVector*-200
                    BV.Parent = Hit
                    Debris:AddItem(BV, .5)
                        
                    if PlayersService:GetPlayerFromCharacter(Hit.Parent) ~= nil then
                        ShakeCamera(PlayersService:GetPlayerFromCharacter(Hit.Parent))
                    end
                end
            end
        end)

The “if not Hit:IsDescendantOf(Character)” means if the “something” was casted by a player, it won’t damage the player, but damage another person when touched. (This script won’t help with your game, but it is something that will get you started.) Hope this helps!

– Drinkinix :smile:

4 Likes

Unfortunately, it didn’t solve my problem. But thanks for telling me about IsDescendantOf, it might come in handy in the future.

1 Like

Aw. That’s a shame. Good luck on fixing your problem. :slightly_smiling_face:

2 Likes

I updated the post. The problem has nothing to do with otherHumanoid ~= humanoid being ignored. Sorry, my assumption made no sense at all. I’ll analyze the script further next time.

1 Like

How can I work around this limitation? I tried changing the Part0, Part1, and Parent of the weld, no luck. I also tried using WeldConstraints and Motor6Ds instead of Welds, and nothing changed at all. Do I have to ignore what I’m trying to do and come up with another hit effect? I hope that’s not the case, or I’ll be very frustrated because I could do such things without complications before they forced us to make games with FilteringEnabled.

1 Like

What exactly isn’t working as of now, what causes it? Does the original character die because the weld is messing with it’s root part or what?

2 Likes

That’s what I want to know. Maybe Roblox doesn’t support character parts being attached to other parts anymore,

1 Like

It seems that no one around here knows, but welding player models together can lead to both dying if one’s humanoid health reaches 0.

I also noticed this, if a character is welded to a character and that character dies then both of them dies, a way to fix this is

							char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)

Set the humanoidstatetype of “dead” of the character being welded, to false

2 Likes