Hello there!
I’ve created an ability to allow the player to parry for my swords, the issue is that the player is still damaged even if they parry it albeit delayed.
local Swords = script.Parent
local ATKAnim = Swords:WaitForChild("ATKAnim")
--Folders
local AnimFolders = {
SA = ATKAnim.SwordAnims
}
--//Services
local UIS = game:GetService("UserInputService")
--//Plr
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
--//Variables
local OnEquip = false
local ParryDB = false
local CanParry = false
--//Func
Swords.Equipped:Connect(function()
OnEquip = true
Humanoid.WalkSpeed = 25
local SwordIdle = Humanoid.Animator:LoadAnimation(AnimFolders.SA.SwordIdle)
SwordIdle:Play()
Swords.Unequipped:Connect(function()
OnEquip = false
Humanoid.WalkSpeed = 16
SwordIdle:Stop()
end)
end)
UIS.InputBegan:Connect(function(i, gp)
if i.KeyCode == Enum.KeyCode.Q and OnEquip and not ParryDB then
ParryDB = true
CanParry = true
local OldHealth = Humanoid.Health
local TryParryAnim = Humanoid.Animator:LoadAnimation(AnimFolders.SA.TryParry)
TryParryAnim:Play()
delay(0.5,function()
TryParryAnim:Stop()
ParryDB = false
CanParry = false
end)
Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if Humanoid.Health <= OldHealth and CanParry == true then
CanParry = false
TryParryAnim:Stop()
local ParryAnim = Humanoid.Animator:LoadAnimation(AnimFolders.SA.SuccessfulParry)
ParryAnim:Play()
Humanoid.Health = OldHealth
end
end)
end
end)