Hi, basically I have a combat system and when you punch a player they get stun, the problem is when two players punch each other at the same time or very nearly, they both get stunned. I’ve already tried debounce and I am already using a stun value but they still dont work if they stun each other at the same time.
Here is a script example to show how you can do it:
so basically lets try to add a stun value to players
(even if stun value wasnt working for you but i dont know which method you used)
--the script is just an example.
HitEvent.OnServerEvent:connect(function(plr,hit)
----the hit variable is the player that got hit
if plr.StunValue == true then return end --end the script if the player that is hitting is stuned
hit.stun() --stun the opponent if the player isnt stunned
end)
whats happening here is that when both player hit each other at the same time, they arent actually hitting at the exact same time its actually player1 got stun then player2 got stun very very fast, so when player1 hit player2 each together at the same time is that one of them should get stun first lets say player2 got stun first so he wont be able to stun player1 as in the script above already ended as his stun value was true.
This is what I’ve been doing
> local function Touched(hit,Number)
> if player.Stun.Value == false then
game.ReplicatedStorage.RemoteEvent.StunValue:FireServer(game.Players:FindFirstChild(hit.Parent.Name).Stun,true)--makes the stun value true
> end
this isnt the only code that activates the stun value or detects the value, for example when they use the m1 it detects the stun value, which is false when they stun each other at the same time or nearly the same time.
Maybe when they try to stun each other you could make a deflect system. Make it so if it detects both of them trying to stun it deflects.
If it deflects does that mean both of them gets unstun?, if so I could try that
Yes indeed so, this would fix the problem and be a cool little thing in your system. Maybe you could make a value that is in the character which is a bool value which is for if they are hitting. Then you could just make a if statement to see if the target is also hitting.
You may need to add a priority check system, you could store the time when player clicks then compared their times to see which is faster and prioritise the one that’s faster. Try to do this server side