The problem I’m facing is whenever an opponent is stuck in stun. My stun management system works as intended, but whenever the attacker leaves the game while the enemy is stunned, the enemy is stunned indefinitely. The idea I want to achieve is for my script to carry on with the stun’s length and do not stun the opponent forever. Thanks in advance.
3 Likes
(Im 100% aware this isn’t the most optimized)
You could store the time of the start of the stun in a variable
-- When player gets stunned
StunTimeManager[player.Name] = tick()
-- Code here to detect when player wants to move
if tick() - StunTimeManager[player.Name] >= stuntime then
-- Unstun them
StunTimeManager[player.Name] = nil
end
This method doesn’t depend on whether the attacker exists or not so you should be able to keep them stunned
1 Like
You could create a table full of stun data with a structure like:
local StunData = {
[Player1] = Player2,
}
On the player removing event, you could loop through the StunData table and see if any player has the player leaving set to them. If they are, you remove both players from the StunData table. It’s best to use the top person’s code if its time-based. Also this is just a random idea but it should work
1 Like
I think that is because the stun time is managed by the clint of the attacker, try to manage it on the server or on the victim.
1 Like