UserInputService problem

So I’m trying to make a system where you can sprint and slide, and when you finish sliding, if you are still holding down on the shift key, you will still be sprinting. But when LeftShift is being held down, UserInputService just Isn’t detecting the C key being pressed. It detects when its been released, but not pressed.

Here is a test version of the code, because I don’t like to leak my scripts.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.C then
			print("C Is pressed")
		end
		
		if input.KeyCode == Enum.KeyCode.LeftShift then
			print("Shift Is pressed")
		end
	end
end)

This code runs without issue, but the true code you’re referring to seems to be where the problem lies. Unfortunately, without that, there’s not much we can do to help. Please keep in mind that sliding and dashing systems are fairly common and can be implemented by many developers; your code is not as proprietary as you think

It’s the base system, just without all the animation stuff. The issue is the input service doesn’t detect the C key being pressed when holding shift down, I tested and this code has the same issue.

Simplest solution is to

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.C and UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) then
			print("C Is pressed")
		end
	end
end)

Explanation is the event will fire individually for each new key even if they are pressed at the same time.

Not sure what to tell you :person_shrugging:

local UserInputService = game:GetService("UserInputService")

local inputMap = {
	[Enum.KeyCode.LeftShift] = Enum.KeyCode.C,
	[Enum.KeyCode.C] = Enum.KeyCode.LeftShift,
}


local function onInputBegan(input: InputObject, gameProcessedEvent: boolean)
	if gameProcessedEvent then
		return
	end
	
	local complimentInput = inputMap[input.KeyCode]
	if not complimentInput then
		return
	end
	
	print(`{input.KeyCode.Name} pressed {if UserInputService:IsKeyDown(complimentInput) then `while holding {complimentInput.Name}` else ""}`)
end


UserInputService.InputBegan:Connect(onInputBegan)

That only works if you press C before Shift. I’m trying to achieve pressing Shift before C.

Did you not read the output? It works in all orders:

image

where exactly did you place the script in explorer?

My script is in StarterPlayerScripts. I doubt the location of the LocalScript affects UserInputService’s ability to read key inputs. Do you have a US QWERTY keyboard?

What is a US QWERTY keyboard?

woah woah these are extra characters to make the character limit!!!

OH, yes I do. I don’t know how that would affect UserInputService though

Other keyboard types have been found to affect the service. You might some some keybind on your PC that is preventing Roblox from recognizing the input

I got the whole idea from the popular(ish) game “Grace” and their (im guessing similar system) works fine.

Okay so for some reason, this issue doesn’t happen in the actual game (not in studio). Idk why this is :sob: