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

Everytime i move they code prints, but the key is q..any help?

Asked by
Jirozu 71
8 years ago
Edited 8 years ago
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Combo = 0


Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key ==  "q" and Combo == 0 then
        wait(.2)
        Combo = 1
        print("PunchRight")

    elseif Combo == 1 then
        wait(.2)
        Combo = 2
        print("PunchLeft")

    elseif Combo == 2 then
        wait(.2)
        Combo = 3
        print("RightKick")

    elseif Combo == 3 then
        wait(.2)
        Combo = 0
        print("LeftKick")
    end
end)
1
More explination to what the code issue is rather than the code itself? GreekGodOfMLG 244 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

A programmer goes to the grocery store...

In your elseif conditions, you fail to check whether the key is q still. As a result, they will check regardless of whether q was pressed at all. A simple solution is to escape at the top.

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Combo = 0


Mouse.KeyDown:connect(function(key)
    key = key:lower()
  if key ~= "q" then return end; -- Escape if q was not pressed.
    if Combo == 0 then
        wait(.2)
        Combo = 1
        print("PunchRight")

    elseif Combo == 1 then
        wait(.2)
        Combo = 2
        print("PunchLeft")

    elseif Combo == 2 then
        wait(.2)
        Combo = 3
        print("RightKick")

    elseif Combo == 3 then
        wait(.2)
        Combo = 0
        print("LeftKick")
    end
end)
Ad

Answer this question