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

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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
Ad

Answer this question