How to put debounces to multiple functions efficiently?
So I'm trying to make a combat system with multiple attacks and I don't want players to be spamming the same attack over and over again.
Was:
01 | local UIS = game:GetService( "UserInputService" ) |
05 | local function attack 1 () |
16 | local function attack 2 () |
27 | local function attack 3 () |
38 | local function attack 4 () |
49 | UIS.InputBegan:Connect( function (input, gameProcessed) |
50 | if input.UserInputType = = Enum.UserInputType.Keyboard then |
51 | if input.KeyCode = = Enum.KeyCode.Q then |
55 | if input.KeyCode = = Enum.KeyCode.E then |
59 | if input.KeyCode = = Enum.KeyCode.Z then |
63 | if input.KeyCode = = Enum.KeyCode.C then |
Attempt No. 1; I thought it was perfect but it didn't work. Please let me know if you do know why.
01 | local UIS = game:GetService( "UserInputService" ) |
03 | local function attack 1 () |
04 | local cooldown = false |
15 | local function attack 2 () |
16 | local cooldown = false |
27 | local function attack 3 () |
28 | local cooldown = false |
39 | local function attack 4 () |
40 | local cooldown = false |
51 | UIS.InputBegan:Connect( function (input, gameProcessed) |
52 | if input.UserInputType = = Enum.UserInputType.Keyboard then |
53 | if input.KeyCode = = Enum.KeyCode.Q then |
57 | if input.KeyCode = = Enum.KeyCode.E then |
61 | if input.KeyCode = = Enum.KeyCode.Z then |
65 | if input.KeyCode = = Enum.KeyCode.C then |
Attempt No. 2
01 | local UIS = game:GetService( "UserInputService" ) |
04 | local cooldown 2 = false |
05 | local cooldown 3 = false |
06 | local cooldown 4 = false |
08 | local function attack 1 () |
19 | local function attack 2 () |
30 | local function attack 3 () |
41 | local function attack 4 () |
52 | UIS.InputBegan:Connect( function (input, gameProcessed) |
53 | if input.UserInputType = = Enum.UserInputType.Keyboard then |
54 | if input.KeyCode = = Enum.KeyCode.Q then |
58 | if input.KeyCode = = Enum.KeyCode.E then |
62 | if input.KeyCode = = Enum.KeyCode.Z then |
66 | if input.KeyCode = = Enum.KeyCode.C then |
Now, the second attempt actually did work. But I want to know if there's a more efficient/simple way to do it. Thank you.