Hello, I’m making a combat system and I’m attempting to disable a player’s ability to attack (via mouse1) when they are attacked. So far I’m using a task.spawn and waiting 1 second before the player is able to attack again. This method is unreliable as the player is eventually able to continue attacking during an m1 combo.
I’m currently thinking of another way, using a heartbeat function and a local script to iterate through an interval and when the player is attacked the interval is set back to 0, and when that interval is reached it fires back to the server allowing the player to attack again.
If anyone has any more reliable ways of going about this, I would appreciate if you would share them, thank you for your time.
(Screenshot of what a player experiences when their attacked)
Sounds like you are trying to implement stun/debounce, but are doing it extremely indirectly.
Here’s my take here, if you want stun that affects movement & attacking - use a Stunned IntValue/attribute (I prefer attributes, but given you use values you’d probably use them).
Whenever the target gets hit, you would increment the Stunned value: target.Stunned.Value += 1 and then, via task.delay you would decrement the value in N seconds, so it returns to 0: target.Stunned.Value -= 1
Considering you also seem to set the WalkSpeed, you can do it whenever adjusting the Stunned value. Just, when you revert it, add a simple check to see whether the target is still stunned or not.
if target.Stunned.Value == 0 then
humanoid.WalkSpeed = 16
end
Whenever the player wants to attack, check if the Stunned value is above 0, in which case return & do nothing.
Would this prevent the player from sneaking in attacks while they’re getting comboed? For example, the issue right now is that after my task.wait(1) in the bottom of my code once the wait is over the player is able to attack while they’re already in a combo, which I’m trying to prevent. Correct me if I’m wrong but wouldn’t this still allow the player being attacked to attack after the N seconds even while they themselves are in a combo?
Yes, that is exactly what my goal was here. If you use a BoolValue to determine stun, it’ll get overridden by already awaiting threads (so, if you get stunned while stunned, the first stun will cancel it out early). Here, whenever a stun ends, it’ll just decrement the value, meaning the stun remains because the value will still be >0
This is what I’m checking for in the local script, specifically if the player presses Mouse1
It’s still pretty much acting the same way, I’m very confused. Would using remote functions help?
I’m thinking of a way that fires an OnClientEvent to the local script that basically increments an interval until it reaches some number and checks a value/attribute to stop the player from being able to attack. Then fires back to the server to allow the player to be able to attack. If the player is hit, then the interval is returned to 0 and the loop continues until it’s complete.
If you did it as I expect it to be, it should work just fine. I am not too certain on how you did it, but let me try to explain where I would put the checks:
Before running melee, so it doesn’t happen in the first place
When the server receives a hit / melee request, check right in the start - reject if stunned.
In theory, this should stop it from interrupting combos???
It’s working now, thank you and sorry for the trouble lol. I must’ve been trying it in an old team test with the code not being updated. I will definitely be thinking about using IntValues like this more often.