I want to make an ability cancelling system. Player1 attacks Player2 while Player2 is using an ability and this ability stops.
I had an idea to do this with a bindable event or bindable function. When Player1 attacks, the attack script runs the function and it is accepted by Player2’s ability script and stops the attack.
Here’s a piece of code to help you understand:
--Player1 attacks
local Event = game.ReplicatedStorage.BindableFunction
hitbox.Touched:Connect(function(hit)
if hit.Parent ~= char and hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") then
if debounce == false then
debounce = true
hitbox:Destroy()
local eChar = hit.Parent
local eHum = eChar:FindFirstChild("Humanoid")
if eHum.Health > 0 then
eHum:TakeDamage(dmg)
local Hit = eHum:LoadAnimation(script.HitAnim)
Hit:Play()
Event:Invoke()
end
end
end
end)
--Player2 ability script
Event.OnInvoke:Connect(function()
--Something that will stop the ability
end)
The problem is that I don’t know how to stop an attack using a function and I’m not sure if it is worth doing it with only one bindable event, because if there are a lot of abilities in the game, then each ability script after each attack on the player will accept this bindable function and do something.
This is my first topic, so I could make mistakes, feel free to correct me.