How to prevent two simultaneous inputs?

This might be a pretty dumb question, but is there a way to prevent two inputs from being fired at the same time? In my game, certain glitches can occur when a player uses two in-game abilities at the same time. There are debounces in place to prevent them from using 1 ability when another is already being used, but I’m not all that sure as to how to prevent 2 from being used at once.

3 Likes

Just set up another debounce checking if any of the abilities are being used. And when any ability is about to be used check for it.

if not abilityIsBeingUsed then
    abilityIsBeingUsed = true
end
2 Likes

When you use an ability, turn on a debounce that prevents the other ability from working. Check the debounce multiple times in case there is some lag.

while true do
    wait(0.1)
    if UsingAnAbility then
        UsingOtherAbility = false
    end
end
1 Like

If you have two different scripts which work on the same input then make one script to handle these requests

2 Likes

In a single-threaded system, these two examples are the same case. You can’t process two inputs at the same time, so the mechanism you describe is fine, you just have something not implemented correctly if the mutex isn’t working.

1 Like

Oh, then I’ll try to see what I can do. Thank you, this actually helped.

1 Like

Checking multiple times will not help. Because Roblox Lua runs on a single physical thread (Lua threads are a completely different concept and also known as coroutines), checking if a flag is set will never result in a race condition. A single flag for if an ability is currently being used and checking it once will work.

Is there a reason why ability 2 cannot use the same check as ability 1 before it runs? From what I’m understanding both abilities need to check if any ability is currently running and the check was already implemented for ability 1. Since the check looks any ability is running, irrespective of the ability that is running the check, you should be able to copy the check to ability 2.

2 Likes