How do I detect who punched first?

So basically in my game when people both punch they both get stunned this isn’t a bug I’m talking about if they punch the same second it will be ugly. I do not have a way to detect who punched first

1 Like

Try add a global/local variable named LastPunched, then in your script try get if a player is punching another player and don’t edit more the variable. If this not answering/helping your problem, maybe you send the part of the script who control punch.

2 Likes

You can add a timeout for players who are hit, so when the first person hits, it puts the other player in timeout for let’s say .5 seconds, and when the second person’s hit registers, then the script will check the timeout and see that player and not do anything.

1 Like

So ill do

if plr.Character.LastPunch - hit.Parent.LastPunch > hit.Parent.LastPunch then
      hit.Parent.Humanoid:TakeDamage(4) -- you punched first
end
1 Like

I think you forgot .Value and also, it should just check if it’s greater than 0. If the hit last punch value is greater than the players, then the expression will be negative. Otherwise it will be greater than or equal to zero.

1 Like

Nono, your getting it wrong. And yes I did forget .Value but I already fixed that! I used os.clock() to detect, I didnt have a timer.

If both of those LastPunch values are using os.clock. How would that expression ever make it so that you punched first. You will always punch last. If you punched first at time 168, the other person punched at 168.5. So 168 - 168.5 = -0.5. That is not greater than 168.5. So even though you punched first, you punched last if you get what I mean. Shouldn’t the line be

if plr.Character.LastPunch.Value < hit.Parent.LastPunch.Value then
    hit.Parent.Humanoid:TakeDamage(4) -- you punched first
end
1 Like

I originally wrote that but I thought it wouldnt work, but thanks.

You just need to add a small check, because the other character might have punched 10 seconds ago, but you really just want to use that check within a range of numbers, when they are close to eachother. Which was your original problem :slight_smile:

2 Likes

Yea my bad on the math but thanks, it could have been a bug people would complain on

1 Like