Created by perhaps#03094
Features:
- AUTO PARRY
-- // Settings
getgenv().parryEnabled = true
local parryDistance = 15
local animationNames = {"Stab", "SwingLeft", "SwingRight", "Blockstab"}
local timeToBlock = 0.23
local blockTime = 0.2
-- // Services
local playersService = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local runService = game:GetService("RunService")
-- // Variables
local localPlayer = playersService.LocalPlayer
local localCharacter = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local localHRP = localCharacter:WaitForChild("HumanoidRootPart")
local serverEvent = replicatedStorage:WaitForChild("ServerEvent1")
-- // Functions
local function getDistance(Part)
if not localCharacter or not localHRP then return math.huge end
return (localHRP.Position - Part.Position).magnitude
end
local function grabCurrentWeapon(Character)
if not Character then return false end
local currentWeapon = Character:FindFirstChild("1")
if not currentWeapon or not currentWeapon:IsA("Tool") then return false end
return currentWeapon
end
local function grabWeaponAttackAnimations(Tool)
if not Tool or not Tool:IsA("Tool") or not Tool:FindFirstChild("Animations") then return false end
local toolAnimations = Tool.Animations:GetChildren()
if #toolAnimations <= 0 then return false end
local attackAnimations = {}
for i, v in pairs(toolAnimations) do
if table.find(animationNames, v.Name) then
table.insert(attackAnimations, v.AnimationId)
end
end
return attackAnimations
end
local function animationPlayed(Humanoid)
if not Humanoid or not Humanoid.Parent then return end
Humanoid.AnimationPlayed:Connect(function(animationTrack)
if not getgenv().parryEnabled or not animationTrack or not animationTrack.Animation or not Humanoid or not Humanoid.Parent or Humanoid.Health <= 0 then return end
local animationId = animationTrack.Animation.AnimationId
local currentWeapon = grabCurrentWeapon(Humanoid.Parent)
if not currentWeapon then return end
local weaponAnimations = grabWeaponAttackAnimations(currentWeapon)
if not weaponAnimations then return end
if table.find(weaponAnimations, animationId) then
local humanoidRootPart = Humanoid.Parent:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return end
if getDistance(humanoidRootPart) <= parryDistance then
task.wait(timeToBlock)
local timePassed = tick()
local oldConnection;
oldConnection = runService.RenderStepped:Connect(function()
if (tick() - timePassed) >= blockTime then
oldConnection:Disconnect()
end
serverEvent:FireServer("blocking")
end)
serverEvent:FireServer("unblocking")
end
end
end)
end
-- // Code
playersService.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local playerHumanoid = character:WaitForChild("Humanoid")
animationPlayed(playerHumanoid)
end)
end)
for i, v in pairs(playersService:GetPlayers()) do
if v == localPlayer or not v.Character then continue end;
local playerHumanoid = v.Character:WaitForChild("Humanoid")
animationPlayed(playerHumanoid)
v.CharacterAdded:Connect(function(character)
local playerHumanoid = character:WaitForChild("Humanoid")
animationPlayed(playerHumanoid)
end)
end