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

I need help with wait function on keydown functions. Is there someone that can help?

I've made a keydown script that whenever you press the letter E, a fireball shoots from your hand. The problem is i wanted to add a wait time between every fireball being shot but whenever i tried adding a wait, the script broke or did not work properly. Can someone help me out with that?

1 answer

✓ Accepted answer

You need to do a debounce. For example, here's a little thing I did.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local debounce = false

mouse.KeyDown:connect(function(key)
	if key == "e" then
		if debounce == false then -- When a key is pressed, check if debounce is set to False, if it is set to true then it will not run.
			debounce = true -- Makes it so the script is disabled.
			local part = Instance.new("Part", game.Workspace) -- Creates a part.
			wait(2) -- The wait time.
			part:Destroy()
			debounce = false -- Reset the debounce to false, the player can press E again.
		end
	end
end

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