Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Keybind Za Warudo is spammable. Any help?

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

✓ Accepted answer

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)

1 comment

0

Ah, it works now. Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.