How can I disable an ability when the enemy is being hit?

I would like that when an enemy is being hit the ability is canceled and that it works for different types of abilities even if they come from different tools
image

Long story short, I’d like that while he’s being hit, he can’t cast any abilities.

2 Likes

If I understand correctly, I would make a boolean value somewhere that is set to true when a player is being attacked and have the enemy’s script first check if that value is true or false.

For instance,

if script.Parent.Parent.IsBeingAttacked.Value == false then
-- Perform ability
else
-- Player being attacked, can't perform
end

This would prevent the player under attack from starting an ability.

1 Like

Disable the attacking scripts of the enemy. The scripts will stop when disabled and reactivate when they get enabled again.

While that is also a very good option, you would have to specify which scripts to disable in this case. If they are all named ‘Skill’, I guess it’s easy enough to get descendants.
Although, if these are client-sided, I do worry it’s much easier for someone to just re-enable the scripts by use of exploits.

Since they are all within a different tool, that wouldn’t be an issue. If they were all under the same tool, you could just add an in pairs loop to fix that.

If specific ones, you could just number them like “skill1” “skill2” etc ig

While that is a possibility, the server will be forced to dedicate some time to searching for and disabling the specified scripts and then enabling them afterwards. Although a menial task, a large server may take a little longer to complete it.
If the script is running already, you might not want to interrupt it, but I’m not sure in this circumstance.

As a rule of thumb, though, I generally don’t like disabling scripts unless I have to.

I’ll try that option, but that will go in the combat script, right Or would it go mostly in the skill script?

So when a player attacks someone else, their attacking script should set the value to True (Server-side script should do this). Then when the defending player tries to perform an ability during this time, their skill script will first check the value, and if it’s true, it won’t perform an ability.
Sorry if I made things less clear lol.

It has been very helpful, thank you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.