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

For Some Reason "Punch left" Prints When i do want it to?

So i was trying to Re-Make a combat i had a while ago Here Is The Script

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

Mouse.KeyDown:connect(function(key)
	key = key:lower()
	if key ~= "q" then return end;
		if Combo == 0 and Enabled == true then
			Enabled = false
			print("PunchRight")
			wait(1)
			Enabled = true
			Combo = 1
		end
		if Combo == 1 and Enabled == true then
			Enabled = false
			print("PunchLeft")
			wait(1)
			Enabled = true
			Combo = 0
		end
	  
end)

But The Real Problem Is At:

if Combo == 1 and Enabled == true then
			Enabled = false
			print("PunchLeft")
			wait(1)
			Enabled = true
			Combo = 0
		end

So for some reason every time i press q the script does what it should, print "Punch Right", but..then Punch Left Prints? anyway i could somehow fixed that to where if i press q again it prints "Punch left" ?? any help will be greatly appreciated!

1 answer

✓ Accepted answer
Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key ~= "q" then return end;
    if Combo == 0 and Enabled == true then
        Enabled = false
        print("PunchRight")
        wait(1)
        Enabled = true
        Combo = 1 --You set Combo to 1 here, then
    end
    if Combo == 1 and Enabled == true then --over here, it checks if Combo is 1, which you just set it to 1.
        Enabled = false
        print("PunchLeft")
        wait(1)
        Enabled = true
        Combo = 0
    end
end)

To fix this, just use an elseif statement. So if the first if is true, then it doesn't run the second function. (vice versa)

Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key ~= "q" then return end;
    if Combo == 0 and Enabled == true then
      Enabled = false
      print("PunchRight")
      wait(1)
      Enabled = true
      Combo = 1
    elseif Combo == 1 and Enabled == true then
      Enabled = false
      print("PunchLeft")
      wait(1)
      Enabled = true
      Combo = 0
    end
end)

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