UserInputService not working properly?

I was making a sprinting system and it seems that UserInputService is kinda broken, LeftShift doesn’t work properly, it only fires every second input, so, if I were to press LeftShift, it’d fire, but if I were to press LeftShift again it won’t fire, and if I were to press it again… it fires… it’s very odd.

It seems that it isn’t just LeftShift though, it also occurs with RightShift, LeftControl, RightControl, and maybe others… is this a bug? I don’t remember this being an issue in the past when making sprinting scripts…

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	
	if Input.KeyCode == Enum.KeyCode.LeftShift then
		print("Sprinting")
	end
end)

UserInputService.InputEnded:Connect(function(Input, IsTyping)
	if IsTyping then return end
	
	if Input.KeyCode == Enum.KeyCode.LeftShift then
		print("Stop sprinting")
	end
end)

I have no issues, try disabling shiftlock.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	
	if Input.KeyCode == Enum.KeyCode.LeftShift then
		print("Sprinting")
	end
end)

UserInputService.InputEnded:Connect(function(Input)	
	if Input.KeyCode == Enum.KeyCode.LeftShift then
		print("Stop sprinting")
	end
end)
1 Like

The issue persists even with shiftlock disabled.

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

UserInputService.InputBegan:Connect(function(Input, _)
	if Input.KeyCode == Enum.KeyCode.LeftShift then
		Humanoid.WalkSpeed += 8
	end
end)

UserInputService.InputEnded:Connect(function(Input, _)
	if Input.KeyCode == Enum.KeyCode.LeftShift then
		Humanoid.WalkSpeed -= 8
	end
end)

This is working for me (the game processed event parameter conflicts with the left shift key so it needs to be removed in order for the script to work).

If this isnt working even with shift lock disabled then you must ask the question of where the script is located and what type of script is it in. It needs to be in a local script and theres certain locations where local scripts will not work. Such as the workspace. If thats broken, then I would next question if you had team create on and needed to manually save the draft. If not that then I would ask if the script is disabled via local script properties.

All places local scripts can be used, you can reference from here.
LocalScript (roblox.com)

Thanks for your reply. I’m aware of how local scripts work, if it weren’t a local script or if it were in a location where it cannot run Lua code, it wouldn’t fire the event at all, however, the way I realised this issue was occurring was because of the print statements… I later found that the issue was unrelated to Studio, and the code I’ve provided works fine now.