Help with Execution script for weapon

I’m trying to making so that when melee weapon does a crit strike, it will one-shot the target after playing the execution animation

for some reason when the animation started my character’s torso just went 90 degree
and the target’s animation doesn’t work at all

UPDATE: the Execute animation is working fine now I figured out that it has something to do with directional movement script

but I still have a problem, I want the target to get locked in front of the player, face the player then play the animation which doesn’t work right now.

Weapon script (got it working)
-- service
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local TagService = game:GetService("CollectionService")

-- variable
local tool = script.Parent
local Debounce = false
local AttackStep = 1
local rootPart

-- weapon setting
local BaseDamage = 20
local HeavyDamage = 40
local Damage -- to set value later :3
local CritChance = 100 -- Lowest is .1 DO NOT set it to 0 otherwise it will break
local DamageMultiplyer = 1.3 -- how much your crit deal

-- Animation stuff
local Idle = Instance.new("Animation")
Idle.AnimationId = "rbxassetid://82389743504697"
local Slash1 = Instance.new("Animation")
Slash1.AnimationId = "rbxassetid://117195817124320"
local Slash2 = Instance.new("Animation")
Slash2.AnimationId = "rbxassetid://81801466608249"
local Stab = Instance.new("Animation")
Stab.AnimationId = "rbxassetid://116820019801079"
local Execute = Instance.new("Animation")
Execute.AnimationId = "rbxassetid://100383429013256"
local IdleTrack = nil
local SlashTrack1 = nil
local SlashTrack2 = nil
local StabTrack = nil
local ExecuteTrack = nil

-- Creating a hitbox using RaycastHitboxV4 (credit to owner of the module, very cool)
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)

local ignore = {player}
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {ignore}
Params.FilterType = Enum.RaycastFilterType.Exclude

local newHitbox = RaycastHitbox.new(script.Parent)
newHitbox.RaycastParams = Params

local chance = math.round(100/CritChance)

for i, v in pairs(tool:GetDescendants()) do
	if v.Name == "GrabBox" then
		table.insert(ignore, v)
	end
end

local function Execution()
	local Performer = script.Parent.Parent:FindFirstChildOfClass("Humanoid")
	local DirectionalMovement = script.Parent.Parent:FindFirstChild("Directional movement")
	if Performer then
		Performer.WalkSpeed = 0
		DirectionalMovement.Enabled = false
		ExecuteTrack = Performer:LoadAnimation(Execute)
		ExecuteTrack.Priority = Enum.AnimationPriority.Action3
		ExecuteTrack.Looped = false
		ExecuteTrack:Play()
		ExecuteTrack.Stopped:Wait()
		Performer.WalkSpeed = 18
		DirectionalMovement.Enabled = true
	end
end

-- basic tool stuff
tool.Equipped:Connect(function()
	tool.Model.Anchored = false
	IdleTrack = script.Parent.Parent.Humanoid:LoadAnimation(Idle)
	IdleTrack.Priority = Enum.AnimationPriority.Idle
	IdleTrack.Looped = true
	IdleTrack:Play()
end)

tool.Unequipped:Connect(function()
	if IdleTrack then
		IdleTrack:Stop()
	end
end)

tool.Activated:Connect(function()
	if Debounce == true then
		return
	else
		Debounce = true
		if AttackStep == 1 then
			Damage = BaseDamage
			SlashTrack1 = script.Parent.Parent.Humanoid:LoadAnimation(Slash1)
			SlashTrack1.Priority = Enum.AnimationPriority.Action
			SlashTrack1.Looped = false
			SlashTrack1:Play()
			AttackStep = 2
			SlashTrack1:GetMarkerReachedSignal("StartHit"):Connect(function(paramString)
				newHitbox:HitStart()
			end)
			SlashTrack1:GetMarkerReachedSignal("StopHit"):Connect(function(paramString)
				newHitbox:HitStop(2)
			end)
			SlashTrack1:GetMarkerReachedSignal("Interuptable"):Connect(function(paramString)
				Debounce = false
			end)
		elseif AttackStep == 2 then
			Damage = BaseDamage
			SlashTrack2 = script.Parent.Parent.Humanoid:LoadAnimation(Slash2)
			SlashTrack2.Priority = Enum.AnimationPriority.Action
			SlashTrack2.Looped = false
			SlashTrack2:Play()
			AttackStep = 3
			SlashTrack2:GetMarkerReachedSignal("StartHit"):Connect(function(paramString)
				newHitbox:HitStart()
			end)
			SlashTrack2:GetMarkerReachedSignal("StopHit"):Connect(function(paramString)
				newHitbox:HitStop(2)
			end)
			SlashTrack2:GetMarkerReachedSignal("Interuptable"):Connect(function(paramString)
				Debounce = false
			end)
		elseif AttackStep == 3 then
			Damage = HeavyDamage
			StabTrack = script.Parent.Parent.Humanoid:LoadAnimation(Stab)
			StabTrack.Priority = Enum.AnimationPriority.Action
			StabTrack.Looped = false
			StabTrack:Play()
			AttackStep = 1
			StabTrack:GetMarkerReachedSignal("StartHit"):Connect(function(paramString)
				newHitbox:HitStart()
			end)
			StabTrack:GetMarkerReachedSignal("StopHit"):Connect(function(paramString)
				newHitbox:HitStop(2)
			end)
			StabTrack.Stopped:wait()
			Debounce = false
		end
	end
end)

newHitbox.OnHit:Connect(function(Hit)
	if Hit.Parent:FindFirstChildOfClass("Humanoid") then
		if Hit.Parent:FindFirstChildOfClass("Humanoid").Health > 0 then
			local newDamage = math.random(chance) == 1 and Damage * DamageMultiplyer or Damage
			if newDamage > Damage then
				Execution()
				TagService:AddTag(Hit.Parent, "Executed")
				Hit.Parent:FindFirstChildOfClass("Humanoid").Health = Hit.Parent:FindFirstChildOfClass("Humanoid").Health - Hit.Parent:FindFirstChildOfClass("Humanoid").MaxHealth
				print("Crit!")
			else
				print("Normal")
			end
			print("Deal ", newDamage, " Damage")
		end
	else
		return
	end
end)

-- when drop a tool and after a few second, anchor the part to prevent it from getting fling around while player is moving
tool.AncestryChanged:Connect(function(child, parent)
	if parent == workspace then
		tool.Model.CanCollide = true
		Debounce = false
		AttackStep = 1
		wait(2)
		tool.Model.Anchored = true
	else
		return
	end
end)

Target script (I have no idea what I'm doing please help me)
local dummy = script.Parent
local hum = dummy:FindFirstChildOfClass("Humanoid")
local CS = game:GetService("CollectionService")
local GettingExecuted = false
hum.BreakJointsOnDeath = false

local function GettingExecuted()
	local Execute = Instance.new("Animation")
	Execute.AnimationId = "rbxassetid://79302780197661"
	local ExecuteTrack = hum:LoadAnimation(Execute)
	ExecuteTrack.Priority = Enum.AnimationPriority.Action3
	ExecuteTrack.Looped = false
	ExecuteTrack:Play()
end

for dummy in CS:GetTagged("Executed") do
	GettingExecuted()
end
1 Like

the target wasn’t facing the player and wasn’t locked in front of player we can use cframe and weld
however if that did not work provide me the output i have added a debugging

local dummy = script.Parent
local hum = dummy:FindFirstChildOfClass("Humanoid")
local CS = game:GetService("CollectionService")
local rootPart = dummy:FindFirstChild("HumanoidRootPart")

assert(hum, "Humanoid not found in dummy")
assert(rootPart, "HumanoidRootPart not found in dummy")

local function GettingExecuted(executor)
    assert(executor, "Executor is nil")
    assert(executor:IsA("BasePart"), "Executor is not a BasePart")
    
    print("Execution started for " .. dummy.Name)

    local lookAt = (executor.Position - rootPart.Position).Unit
    lookAt = Vector3.new(lookAt.X, 0, lookAt.Z).Unit
    rootPart.CFrame = CFrame.new(rootPart.Position, rootPart.Position + lookAt)
    print("Dummy faced executor")

    local weld = Instance.new("WeldConstraint")
    weld.Part0 = rootPart
    weld.Part1 = executor
    weld.Parent = rootPart
    assert(weld.Parent == rootPart, "Weld failed to parent to rootPart")
    print("Dummy locked to executor")

    local Execute = Instance.new("Animation")
    Execute.AnimationId = "rbxassetid://79302780197661"
    local ExecuteTrack = hum:LoadAnimation(Execute)
    assert(ExecuteTrack, "Failed to load animation")
    ExecuteTrack.Priority = Enum.AnimationPriority.Action3
    ExecuteTrack:Play()
    print("Execution animation started")

    ExecuteTrack.Stopped:Wait()
    print("Execution animation finished")
    weld:Destroy()
    print("Weld destroyed")
end

local function onTagAdded(taggedDummy)
    if taggedDummy == dummy then
        print("Executed tag added to " .. dummy.Name)
        local executors = CS:GetTagged("Executor")
        assert(#executors > 0, "No executor found")
        local executor = executors[1]
        assert(executor:IsA("Model") or executor:IsA("BasePart"), "Executor is not a Model or BasePart")
        local executorPart = executor:IsA("Model") and executor.PrimaryPart or executor
        assert(executorPart, "Executor has no PrimaryPart")
        GettingExecuted(executorPart)
    end
end

CS:GetInstanceAddedSignal("Executed"):Connect(onTagAdded)
print("Script initialized for " .. dummy.Name)

Here is a file of my current progress which should have everything about the tool in there (if you find an error outside of the Execution script please tell me)

Press “E” while pointing your mouse at the tool to pick it up

the crit rate is jacked up to 100 rn so it will crit every strike
crit multiplier doesn’t have a use at the moment since in this case crit damage will always one-shot kill
if you sliding toward the tool after press e it is intensional

CustomToolPickUp.rbxl (114.8 KB)