Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Keybind Za Warudo is spammable. Any help?

Asked by 5 years ago

So I'm trying to make the Za Warudo from JoJo's Bizzare Adventure. Pressing Q will send an event to a server script and the server script does the rest of the work. The thing is, the first press is fine; not spammable. But anything after that, you can constantly spam Za Warudo's. Any assistance? Something I did wrong or something I should do in the script? All help is appreciated. [P.S: It's probably something I did wrong with the debounce but I don't know what it is.]

01local UIS = game:GetService("UserInputService")
02local Event = game:GetService("ReplicatedStorage"):WaitForChild("Events").Abilities.ZaWarudo
03local Player = game.Players.LocalPlayer
04local Debounce = false
05 
06UIS.InputBegan:Connect(function(input)
07    if input.KeyCode == Enum.KeyCode.Q then
08 
09        if not Debounce then
10        Debounce = true
11        print("Za Warudo triggered by "..Player.Name..".")
12        Event:FireServer(Player)
13        end
14    end
15    wait(20)
16    Debounce = false
17end)

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Put the wait inside of the if statement for your debounce. The only reason it should wait 20 is for your debounce; the only way it should get to that point is if the debounce is passed. When you put it outside of your if statement, you're forcing the player to repeatedly wait 20 even when they haven't passed the debounce check, since it's outside of that scope.

The reason it isn't waiting is because you're making the debounce false after any key press, not just Q. The player can spam any key to re-fire the event which causes the wait to repeat in on itself, which essentially causes there not to be a wait.

01local UIS = game:GetService("UserInputService")
02local Event = game:GetService("ReplicatedStorage"):WaitForChild("Events").Abilities.ZaWarudo
03local Player = game.Players.LocalPlayer
04local Debounce = false
05 
06UIS.InputBegan:Connect(function(input)
07    if input.KeyCode == Enum.KeyCode.Q then
08        if not Debounce then
09            Debounce = true
10            print("Za Warudo triggered by "..Player.Name..".")
11            Event:FireServer(Player)
12            wait(20)
13            Debounce = false
14        end
15    end
16end)
0
Ah, it works now. Thanks Daemonophobiaa 37 — 5y
Ad

Answer this question