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

I'm trying to make a keybind script that is timed, it keeps failing. What is wrong with it?

Asked by 9 years ago

I am trying to make a script that has 2 keybinds. 1 starts a timer that in this time slot the other can be pressed. I have it in a local script.

local player = script.Parent.Parent.Parent
local char = player.Character
local torso = char.Torso
local going = false
local timer = 0
local deb = false
local mouse = player:GetMouse()
function normaltorotate()
    torso.CFrame = torso.CFrame *CFrame.Angles(0,1,0)
    going = true
    print('rotated')
    torso.Anchored = true
end
function pulsedet()
    print('detonation')
    torso.Anchored = false
end
mouse.KeyDown:connect(function(rotate, pulse)
    if rotate == 'f' and not deb then
        deb = true
        normaltorotate()
        while going do
            if pulse == 'g' and going then
                pulsedet()
            end
            timer = timer+1
            if timer >= 5 then
                timer = 0
                beb = false
                torso.Anchored = false
                going = false
            end
            wait(.5)
        end
    end
end)

1 answer

Log in to vote
1
Answered by
Muoshuu 580 Moderation Voter
9 years ago

KeyDown only returns a single argument, meaning 'pulse' is always going to be nil.

0
so the keydown would have to be in the loop? User#600 0 — 9y
0
got it :D thx User#600 0 — 9y
0
What? Muoshuu 580 — 9y
Ad

Answer this question