UserInputService not working

I was creating a sprint and crouch system but found out that studio was glitched as if you held down shift and pressed C, it would not detect you pressing C, only releasing. Here is a file of the example in game, you can try it out and look at the Output. This only happens for the C key too.
BrokenUserInput.rbxl (52.8 KB)

Can Roblox fix this issue.

5 Likes

Uhh can you give me the code? Normally pressing both buttons UIS would detect it…
I mean literally type the code out.

1 Like

You can download the link i put in the message and the code is in StarterPlayerScripts

No just type it out. No one is going to download it just to resolve your problem.

2 Likes

this is the code:

local userInputService = game:GetService(“UserInputService”)
userInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
print(“C/Control pressed”)
elseif input.KeyCode == Enum.KeyCode.LeftShift then
print(“Left Shift pressed”)
end
end)

userInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
print(“Left Shift released”)
elseif input.KeyCode == Enum.KeyCode.C then
print(“C/Control released”)
end
end)

ScreenShot might make it easier
Screenshot 2024-09-29 204820

2 Likes

this means that when Left Shift is held C would not be regarded, because of the if statement.

Are you sure, because I replaced C with F and it works fine. Otherwise how would I fix it?


I also have video evidence that the keycode C is glitched.

Ok then try this (a test):

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
  if input.KeyCode == Enum.KeyCode.C then
    print("C is being pressed")
  end
end)

It works normally, this means that C only doesnt work when holding down the shift key. Do I report this as a bug to roblox?

Well that’s odd. It seems to be an error as it’s also not working for me…

1 Like

Thanks for the help, ill start a new post reporting the bug.

local userInputService = game:GetService("UserInputService")
local pressedshift = false
local pressedC = false
userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C and not pressedshift then
		pressedC = true
		print("C/Control pressed")
	end
	if input.KeyCode == Enum.KeyCode.LeftShift and not pressedC then
		pressedshift = true
		print("Left Shift pressed")
	end
end)

userInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift and pressedshift == true then
		pressedshift = false
		print("Left Shift released")
    end
	if input.KeyCode == Enum.KeyCode.C and pressedC == true then
		pressedC = false
		print("C/Control released")
	end
end)

Just tested it, this didnt work.

The problem seems to be caused by weird errors.

Values can help you to detect if it pressed or not

tiny bit late however currently Shift + C/X are new binds being used with the update for grid snapping (i think), if you want to disable it then you can unbind the hotkeys, your script will work as intended in the actual game itself, hope this helps :+1:
[edit]: sorry forgot to include this originally however you can disable them via File (in the top left of your screen), then click Studio Settings, click the Studio tab and scroll down until you see “Respect Studio shortcuts when game has focus” and disable it, that should solve your issue

2 Likes

@ItzzViperr You can probably override this behavior by instead using ContextActionService. Try it out, I will write a script soon but heres the link to the docs for now ContextActionService | Documentation - Roblox Creator Hub

edit: sorry i forgot to make that script, contact me if you still need it since the post is now solved
also i didnt see that wetro said how to disable it too that’s my fault

2 Likes

well that explains it.

USELESS PLACEHOLDER TEXT

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.