Player Stun Difficulties

I’ve been having this problem for a while, so each time I smack a player in the head their speed is set to 0 then quickly back to default speed for a chance to combo.

But the problem is the previous stun will set the speed back to default even if you hit the player again because it’s still running. How can I fix this?

E.g of my script;

function changeSpeed()
playerspeed = 0
wait(.1)
playerspeed = defaultspeed
end

FYI I can’t use a coroutine and yield it each time a player gets smacked in the head, because I’m using a module script in ReplicatedStorage and it’s global for everyone.

I’m not exactly sure what to call it- I think it might be called a debounce- but you could do something along the lines of:

function changeSpeed()
    Hitting = not Hitting
    local State = Hitting

    playerspeed = 0
    wait(.1)

    if State == Hitting then
        playerspeed = defaultspeed
    end

end

By having the not Hitting line, we’re able to make multiple hits swap around the value, to disable the previous hit from resetting to default. Furtherly by having the State variable to check Hitting against, the script will ONLY reset the player’s speed back to default if another hit has not been processed and caused this hit to disarm.

This will probably take some adjusting for your scenario and the rest of your script, but I hope this is helpful! :slightly_smiling_face:

The module script is global so adding a debounce would effect other players stuns. There may be another way to go about this though as it could work.

I’ve done something similar to this before.

currentThread[player] = 0

function changeSpeed()
local newThread = currentThread[player] + 1
currentThread[player] = newThread
playerSpeed = 0
delay(0.1, function()
if currentThread[player]  == newThread then
playerSpeed = defaultSpeed
end
end)
end

Just keep track of the amount of times you run it for the same player, and then you can just see if there has been a punch in the 0.1 settings you yielded for.

3 Likes

Figured it would be something simple like that thanks!

1 Like