Im trying to make a stun system for my combat game. So far the stun system kind of works. The opponent getting attacked kinda cant attack back in a combo. The opponent after 0.75 seconds can attack back even in a combo.
Im trying to figure out how to make the opponent get stunned longer when hit by another m1.
if statsfol.Stunned2.Value < 0.15 then
statsfol.Stunned2.Value = 0.15
end
I can’t really explain very well why this would be more efficient it might not even fix your solution, but it’s worth a try. All I can say is it’s probably not the best idea to only wait until the values 0 when you reset it back to 0.15 per hit.
Roblox runs at 60 fps, so the least amount of time you can wait for is ~0.017.
If you want to wait for one frame, use the Heartbeat or RenderStepped events.
Also, use task.wait(n), its the upgraded version of wait(n)
For the stun system, I would recommend using a counter, e.g.
local stunCounter = 0
function Stun(char, stunTime)
stunCounter += 1 -- increments every time a stun occurs
local stunNumber = stunCounter
char.Stunned = true
task.wait(stunTime)
if stunNumber == stunCounter then -- if its not equal, another stun is occuring
char.Stunned = false
end
end
This method won’t stack stun, but makes stun follow up on each other, which imo is better.
If this is a server-side stun, then you will need to give each character their unique stun counter, like:
I think your issue is that the variable resets only when it hits 0. You’ll want to try something like I did above, because if you don’t then if you punch a player twice the second punch won’t reset the timer because it will not be 0.
I hope this helps, I’m almost certain this is the problem as well especially if your combos are kind of slow.