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.]
local UIS = game:GetService("UserInputService") local Event = game:GetService("ReplicatedStorage"):WaitForChild("Events").Abilities.ZaWarudo local Player = game.Players.LocalPlayer local Debounce = false UIS.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.Q then if not Debounce then Debounce = true print("Za Warudo triggered by "..Player.Name..".") Event:FireServer(Player) end end wait(20) Debounce = false end)
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.
local UIS = game:GetService("UserInputService") local Event = game:GetService("ReplicatedStorage"):WaitForChild("Events").Abilities.ZaWarudo local Player = game.Players.LocalPlayer local Debounce = false UIS.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.Q then if not Debounce then Debounce = true print("Za Warudo triggered by "..Player.Name..".") Event:FireServer(Player) wait(20) Debounce = false end end end)