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.]

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)

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.

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)

0
Ah, it works now. Thanks Daemonophobiaa 37 — 5y
Ad

Answer this question