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