I am trying to make a shift to sprint script in my game and when I type my script, it doesn’t work. It doesn’t show the print statement and it doesn’t show any errors when I press shift. This makes no sense because I did a shift to sprint script before and it didn’t get buggy like this. My code is being shown below and help is appreciated and thank you in advance.
local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
UIS.InputBegan:Connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.LeftShift then
print("Left shift was pressed by " .. plr.Name)
end
end)
For your information, if the script isn’t a LocalScript, it won’t work(UserInputService depends on client). If the script is incorrectly parented, it will not work either. It could be either issues.
This can happen if you have mouse lock enabled or bound to the left shift key. PlayerModule is greedy for the keys bound to mouse lock. After it toggles the mouse lock it will sink any subsequent input to the key. Here’s what happens when I turn shift lock off and run your exact same code: