Why does my tool keep killing me?

I was making a special attack for my melee weapon until i noticed that if the npc dies, i die too

my code:

event.OnServerEvent:Connect(function()
	tool.Stop.Value = true
	local Speed = tool.Parent.Humanoid.WalkSpeed
	
	for i,v in tool.Parent.Humanoid.Animator:GetPlayingAnimationTracks() do
		v:Stop()
	end
	tool.Parent.Humanoid.Animator:LoadAnimation(tool.Anims.Special.SpeciaMovel):Play()
	local anim:AnimationTrack = tool.Parent.Humanoid.Animator:LoadAnimation(tool.Anims.Special.SpeciaKill)
	wait(0.5)
	local hits = HitboxHand.CreateHitbox(3,tool.Parent.PrimaryPart)
	local target:Model = nil
	for i, v in hits do
		if v.Parent:FindFirstChild("Humanoid") then
			target = v.Parent
		end
	end
	
	if target then
		target.Torso.CFrame = tool.Handle.Point.WorldCFrame
		target:FindFirstChild("Humanoid").PlatformStand = true
		local weld = Instance.new("WeldConstraint", tool.Handle)
		weld.Part0 = tool.Handle
		weld.Part1 = target.Torso
		wait(0.1)
		
		anim:Play()
		anim:GetMarkerReachedSignal("squash"):Wait()
		tool.Handle.Point.Blood:Emit(50)
		tool.sounds.Special.crush:Play()
		target:FindFirstChild("Humanoid"):TakeDamage(20)
		anim:GetMarkerReachedSignal("squash"):Wait()
		tool.sounds.Special.crush:Play()
		tool.Handle.Point.Blood:Emit(50)
		target:FindFirstChild("Humanoid"):TakeDamage(20)
		
		anim:GetMarkerReachedSignal("yeet"):Wait()
		weld:Destroy()
		target:FindFirstChild("Humanoid").PlatformStand = false
		target.PrimaryPart:ApplyImpulse(tool.Parent.PrimaryPart.CFrame.LookVector * 500)
	end
	
	
	tool.Stop.Value = false
end)
1 Like

i believe the player is also getting hit by the hitbox, and you don’t really have a check to make sure the hitbox does not kill the player

add a check to make sure the target is not the character model of the user thats using the weapon

i added the target check but still the player keeps dying once the npc dies

I managed to replicate the problem, apperantly its about welding and happens when you weld character’s limbs to the dying humanoid’s limbs. (HumanoidRootPart counts tho)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.