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)