-- Parry Tool with Optimized Tracking
local Tool = script.Parent
local COOLDOWN = 1.5
local PARRY_DURATION = 0.5
local KNOCKBACK_FORCE = 30
local UPWARD_FORCE = 15
local RAGDOLL_DURATION = 1.2
local IMMUNITY_DURATION = 1.0
local PARRY_RADIUS = 8
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DeathTracker = require(ReplicatedStorage:WaitForChild("DeathTracker"))
local PARRY_ANIM_ID = "rbxassetid://121182370908826"
local Parrying = false
local CanParry = false
local Equipped = false
local MyHumanoid, MyCharacter, MyPlayer
local ParryAnimTrack
Tool.TextureId = ""
local function PlayParryAnimation()
if not MyHumanoid then return false end
code
if ParryAnimTrack then
ParryAnimTrack:Stop()
ParryAnimTrack:Destroy()
end
local anim = Instance.new("Animation")
anim.AnimationId = PARRY_ANIM_ID
ParryAnimTrack = MyHumanoid:LoadAnimation(anim)
ParryAnimTrack.Priority = Enum.AnimationPriority.Action
ParryAnimTrack.Looped = false
ParryAnimTrack:Play()
return true
end
local function CreateSparks(position)
local SparkTemplate = ReplicatedStorage:FindFirstChild("Sparks")
if not SparkTemplate then return end
local function ApplyParryKnockback(character, direction)
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp then
local bv = Instance.new("BodyVelocity")
bv.Velocity = direction * KNOCKBACK_FORCE + Vector3.new(0, UPWARD_FORCE, 0)
bv.MaxForce = Vector3.new(1e5, 1e5, 1e5)
bv.P = 5e4
bv.Parent = hrp
Debris:AddItem(bv, 0.2)
end
end
local function ParryRagdollCharacter(character, direction)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or humanoid:GetAttribute("RagdollImmunity") then return end
code
-- Record attack before applying effects
DeathTracker.RecordAttack(character, MyPlayer)
humanoid:SetAttribute("RagdollImmunity", true)
humanoid.PlatformStand = true
ApplyParryKnockback(character, direction)
task.delay(RAGDOLL_DURATION, function()
if humanoid and humanoid.Parent then
humanoid.PlatformStand = false
task.wait(IMMUNITY_DURATION)
if humanoid and humanoid.Parent then
humanoid:SetAttribute("RagdollImmunity", false)
end
end
end)
end
local function CheckParryHitbox()
if not MyCharacter then return end
local myRoot = MyCharacter:FindFirstChild("HumanoidRootPart")
if not myRoot then return end
code
for _, player in ipairs(Players:GetPlayers()) do
if player ~= MyPlayer then
local char = player.Character
if char then
local targetRoot = char:FindFirstChild("HumanoidRootPart")
if targetRoot then
local distance = (targetRoot.Position - myRoot.Position).Magnitude
if distance <= PARRY_RADIUS then
local direction = (targetRoot.Position - myRoot.Position).Unit
direction = (direction + Vector3.new(math.random(-10,10)/100, math.random(5,15)/100, math.random(-10,10)/100)).Unit
-- Only create sparks if we actually hit someone
local sparkPosition = myRoot.Position + (myRoot.CFrame.LookVector * 3) + Vector3.new(0, 1.5, 0)
CreateSparks(sparkPosition)
ParryRagdollCharacter(char, -direction)
return true
end
end
end
end
end
return false
end
local function OnActivated()
if Parrying or not Equipped or not MyHumanoid then return end
Parrying = true
CanParry = true
code
if not PlayParryAnimation() then
Parrying = false
CanParry = false
return
end
-- Only show sparks if hit is successful
local hitSuccess = CheckParryHitbox()
task.delay(PARRY_DURATION, function()
CanParry = false
if ParryAnimTrack then
ParryAnimTrack:Stop()
ParryAnimTrack:Destroy()
ParryAnimTrack = nil
end
end)
task.delay(COOLDOWN, function()
Parrying = false
end)
end
local function OnEquipped()
Equipped = true
MyCharacter = Tool.Parent
MyHumanoid = MyCharacter:FindFirstChildOfClass("Humanoid")
MyPlayer = Players:GetPlayerFromCharacter(MyCharacter)
end
local function OnUnequipped()
Equipped = false
if ParryAnimTrack then
ParryAnimTrack:Stop()
ParryAnimTrack:Destroy()
ParryAnimTrack = nil
end
MyCharacter = nil
MyHumanoid = nil
MyPlayer = nil
CanParry = false
Parrying = false
end
I need to fix this roblox script, the parrying is an attack instead of a defensive thing, Its only supposed to parrying should just be if the player is parrying, and they get punched, it knocks back the person who got parried instead of the person who did the parry.
Assistant
To fix the parry tool so that it functions as a defensive ability (knocking back the attacker instead of the target), we need to restructure the logic to track the attacker when the player is hit, and then knock them back during a successful parry. The current code is structured for an offensive attack, not a defensive action.
✅ Key Fixes Needed
Track the attacker when the player is hit (e.g., via damage event).
Modify the parry logic to knock back the attacker, not any player in range.
Ensure the parry is triggered by the player being attacked, not by manual activation.
🛠️ Step-by-Step Fixes
1. Track the Attacker
Add a variable to store the attacker and a function to detect when the player is hit.
lua
local Attacker = nil
-- Function to detect when the player is hit
local function OnDied()
-- This is a placeholder. You'd need to attach this to the player's Humanoid's Died event.
-- Alternatively, use a damage event.
end
local function OnHit(hit, attacker)
Attacker = attacker
-- Optionally, trigger a visual or audio cue for the player
end
⚠️ Note: You’ll need to implement the actual damage detection (e.g., using Humanoid.Touched or Hit events) to capture the attacker.
2. Modify the Parry Logic
Update the OnActivated function to knock back the attacker instead of any player in range.
lua
local function OnActivated()
if Parrying or not Equipped or not MyHumanoid then return end
Parrying = true
CanParry = true
if not PlayParryAnimation() then
Parrying = false
CanParry = false
return
end
-- Only knock back the attacker if they exist
if Attacker then
local attackerChar = Attacker.Character
if attackerChar and attackerChar:FindFirstChild("HumanoidRootPart") then
local direction = (MyCharacter.HumanoidRootPart.Position - attackerChar.HumanoidRootPart.Position).Unit
ApplyParryKnockback(attackerChar, -direction)
CreateSparks(MyCharacter.HumanoidRootPart.Position + Vector3.new(0, 1.5, 0))
end
end
task.delay(PARRY_DURATION, function()
CanParry = false
if ParryAnimTrack then
ParryAnimTrack:Stop()
ParryAnimTrack:Destroy()
ParryAnimTrack = nil
end
end)
task.delay(COOLDOWN, function()
Parrying = false
end)
end
3. Update ParryRagdollCharacter (Optional)
If you still want to use this function, you can remove it and replace it with the ApplyParryKnockback directly in OnActivated.
🧠 Summary of Changes
Feature
Before
After
Trigger
Manual activation (attack)
Triggered by being hit (defensive)
Knockback Target
Any player in range
Only the attacker
Logic
Offensive attack
Defensive counter
🔧 Final Notes
You’ll need to implement damage detection (e.g., using Humanoid.Touched or Hit events) to properly track the attacker.
The OnHit function is a placeholder — you must bind it to the player's damage events.
This approach assumes the attacker is a player character. If the attacker is an NPC or projectile, adjust accordingly.
✅ Example Damage Detection (Optional)
lua
local function OnHit(hit)
local attacker = hit.Parent
if attacker and attacker:FindFirstChild("Humanoid") and attacker ~= MyCharacter then
Attacker = attacker
-- Trigger parry logic
end
end
MyCharacter.Humanoid.Touched:Connect(OnHit)
By restructuring the logic to track the attacker and knock them back during a successful parry, the tool will now act as a defensive ability as intended.