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

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

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 comment

1

More explination to what the code issue is rather than the code itself?

1 answer

✓ Accepted answer

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)

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