so the cooldown works only one time but it breaks after. some guy told me to make 2 debounces, 1 to make sure you don't deactivate the cooldown numerous times, and one for the actual cooldown but i don't really understand what i have to do since i am a beginner. Can someone help me?
01 | local play = game.Players.LocalPlayer |
02 | local uis = game:GetService( "UserInputService" ) |
03 | local Character = play.Character or play.CharacterAdded:wait() |
04 | local a = script.Parent.Animations.Blocking |
05 | local b = play.Character:WaitForChild( "Humanoid" ):LoadAnimation(a) |
06 | local debounce = false |
07 | local remote = game.ReplicatedStorage:WaitForChild( "blockinge" ) |
08 | uis.InputBegan:Connect( function (input, gameProcessed) |
09 | if input.KeyCode = = Enum.KeyCode.F and not gameProcessed and not debounce then |
10 | debounce = true |
11 | remote:FireServer() |
12 | b:Play() |
13 | end |
14 | end ) |
15 |
No, you don't need a second debounce and I'm not sure what that person was thinking, the real problem here is that you are not setting the debounce back to false.
1 | if input.KeyCode = = Enum.KeyCode.F and not gameProcessed and not debounce then |
2 | debounce = true |
3 | remote:FireServer() |
4 | b:Play() |
5 | wait( 1 ) -- This can be however long you want. |
6 | debounce = false |
7 | end |
Might I ask why you are doing the debounce on the client? This can be spoofed by exploiters and they will be able to cheat in your game, so I recommend doing the debounce on the server. (You will need to give each player their own debounce value to do this, and it will not be done in a local script.)