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.
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.
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.
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)