UserInputService.InputBegan issue

This is my first time making a Topic so sorry if I make any mistakes.

My game is a fighting game, in which I of course need to register player inputs to perform specific moves, those inputs being the numbers from 1 to 7 on your keyboard.
The script worked perfectly until ROBLOX updated, I don’t know if it’s because of that or if I messed anything up. I’ve only tried using UserInputService because it’s the most reliable.
This is my code:

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input,GameProcessedEvent)
	if not GameProcessedEvent then
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
				LMB()
		elseif input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.F then
				F()
			elseif input.KeyCode == Enum.KeyCode.One then
				moveone()
			elseif input.KeyCode == Enum.KeyCode.Two then
				movetwo()
			elseif input.KeyCode == Enum.KeyCode.Three then
				movethree()
			elseif input.KeyCode == Enum.KeyCode.Four then
				movefour()
			elseif input.KeyCode == Enum.KeyCode.Five then
				movefive()
			elseif input.KeyCode == Enum.KeyCode.Six then
				movesix()
			end
		end
	end
end)

By the way, the functions work, they aren’t the issue here.
It works in Studio but not in ROBLOX player.

1 Like

You forgot the parentheses here:

movetwo()

Right, sorry about that, but that’s still not the issue, just the fact i typed it manually. I’ll edit it and fix it.

Are there any errors that are occurring? Have you tried using print statements to see which if statement isn’t being reached?

It looks like 1 and 2 work consistently while 3,4 and 5 are very janky and often don’t work.
LMB works but after a bit it stops working??
I don’t think it’s an issue with the moves themselves because they used to work perfectly and I didn’t change anything about them.
No errors either.

As I said though, they work perfectly in studio, which is weird.

Could it possibly be a ping problem?

You don’t need to check if the user input type is a keyboard.
Try this:

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, GameProcessedEvent)
	if not GameProcessedEvent then
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			LMB()
		end
		if input.KeyCode == Enum.KeyCode.F then
			F()
		elseif input.KeyCode == Enum.KeyCode.One then
			moveone()
		elseif input.KeyCode == Enum.KeyCode.Two then
			movetwo()
		elseif input.KeyCode == Enum.KeyCode.Three then
			movethree()
		elseif input.KeyCode == Enum.KeyCode.Four then
			movefour()
		elseif input.KeyCode == Enum.KeyCode.Five then
			movefive()
		elseif input.KeyCode == Enum.KeyCode.Six then
			movesix()
		end
	end
end)

Also I recommend you to put all the keycodes and stuff into a table and use a pairs loop to check for them.

Checking if user input type is a keyboard or not didn’t change anything.

Don’t think it is, considering it would just make the moves come out later instead.

Then try to change all the elseif statements to if statements. See if it works.

Still the same problem, nothing changed.

Have you tried adding a debounce so the input function doesn’t fire more than once?

That’s in the moves themselves, added it to the input check and it still doesn’t change anything.

Have you changed anything in the moves script?

No, considering they used to work right before ROBLOX upgraded last time. What should I change? The moves usually function like this:

if movecooldown == true then return end
movecooldown = true
--move scripting here
wait(cooldown amount)
movecooldown = false

This probably wont fix your issue but you should probably make your code more clean with a lookup table

local Keybinds = {
   [Enum.KeyCode.F = F
   [Enum.KeyCode.One] = moveone
   [Enum.KeyCode.Two] = movetwo
   [Enum.KeyCode.Three] = movethree
   [Enum.KeyCode.Four] = movefour
   [Enum.KeyCode.Five] = movefive
   [Enum.KeyCode.Six] = movesix
}

UIS.InputBegan:Connect(function(input, GameProcessedEvent)
	if GameProcessedEvent then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		LMB()
    elseif Keybinds[input.KeyCode] then 
        Keybinds[input.KeyCode]() 
    end
end)
1 Like

This actually fixed it I think, thank you!
You also helped me clean up my code so thanks for that as well!

Question though, how do I do something like:

move1(true)
move1(false)

Basically using the same move but with different outcomes if it’s true or false.

You can put a parameter in the function and put different outcomes for each value you want