I want to add a feature to my Combat System where you can cancel one’s move, how would I execute this properly? If anyone has any ideas to what features I could use, please let me know!
I’ll paste the code I wrote for my moves so that way you can get a general idea on what I’m trying to do here, basically trying to cancel a move.
--Services
local RS = game:GetService('ReplicatedStorage')
local Debris = game:GetService('Debris')
--Modules
local CombatSystem = require(RS.Modules.CombatSystem)
--Remote Events
local ability = RS.RemoteEvents.CombatStyle.ability
local tripleCombo = script.Parent.Animations.VictimPlayer.AbilityAnims.tripleCombo
local victimAnims = {
tripleCombo.tcHurt1,
tripleCombo.tcHurt2,
tripleCombo.tcHurtFinal
}
local animCount
ability.OnServerEvent:Connect(function(player, combatAbility)
local char = player.Character
local hum = char.Humanoid
local Animator = hum.Animator
local charParts = {
char.RightHand,
char.LeftHand
}
if combatAbility == 2 then
animCount = 0
local tripleComboAnim = script.Parent.Animations.Player.AbilityAnims.tripleComboAnim
Animator:LoadAnimation(tripleComboAnim):Play()
if animCount > 3 then
animCount = 1
end
delay(0.3,function()
local hitbox = script.Parent.Abilities.PunchHitbox:Clone()
hitbox.Parent = workspace.Assets.Hitboxes
hitbox.CFrame = charParts[1].CFrame
Debris:AddItem(hitbox,0.6)
animCount += 1
local weld
local function weldToPart(part, hitbox)
weld = Instance.new('WeldConstraint')
weld.Part0 = part
weld.Part1 = hitbox
weld.Parent = hitbox
end
weldToPart(charParts[1],hitbox)
local connect
local function affectVictim(hitbox,dmg,count)
connect = hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') and not hit:IsDescendantOf(char) then
connect:Disconnect()
local victimChar = hit.Parent
local victimHum = hit.Parent.Humanoid
local victimHumrp = hit.Parent.HumanoidRootPart
local victimAnimator = victimHum.Animator
--Damage
victimHum:TakeDamage(dmg)
--Stun Time
CombatSystem.setStunTime(victimChar,30)
--Knockback
if dmg == 15 then
local knockback = Instance.new('BodyVelocity')
knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
knockback.P = math.huge
knockback.Velocity = -victimHumrp.CFrame.LookVector * 20 + Vector3.new(0,20,0)
knockback.Parent = victimHumrp
Debris:AddItem(knockback,1)
end
--Animations
local hurtAnim = victimAnims[animCount]
victimAnimator:LoadAnimation(hurtAnim):Play()
--VFX
local hitParticle = script.Parent.VFX.TripleComboHit:Clone()
hitParticle.Parent = victimHumrp
delay(0.2,function()
hitParticle.Enabled = false
Debris:AddItem(hitParticle,1)
end)
end
end)
end
affectVictim(hitbox,8,animCount)
wait(0.7)
weld:Destroy()
animCount += 1
local hitbox1 = script.Parent.Abilities.PunchHitbox:Clone()
hitbox1.Parent = workspace.Assets.Hitboxes
hitbox1.CFrame = charParts[2].CFrame
Debris:AddItem(hitbox1,0.6)
weldToPart(charParts[2], hitbox1)
affectVictim(hitbox1,8,animCount)
wait(0.9)
animCount += 1
local hitbox2 = script.Parent.Abilities.PunchHitbox:Clone()
hitbox2.Parent = workspace.Assets.Hitboxes
hitbox2.CFrame = charParts[1].CFrame
Debris:AddItem(hitbox2,0.6)
weldToPart(charParts[1], hitbox2)
affectVictim(hitbox2,15,animCount)
end)
end
end)```