I'm trying to create a script that when the left shift key is pressed, it fires a remoteevent to make the player crouch. However, absolutely nothing happens. It doesn't print anything, but I also don't get any errors.
local crouch = game.ReplicatedStorage.Crouch
UIS = game:GetService('UserInputService')
UIS.InputBegan:connect(function(input,processed)
if not processed then
if input.KeyCode == Enum.KeyCode.LeftShift then
print("leftshift pressed")
crouch:FireService("yes")
end
end
end)
UIS.InputEnded:connect(function(input,processed)
if not processed then
if input.KeyCode == Enum.KeyCode.LeftShift then
print("leftshift pressed release")
crouch:FireService("No")
end
end
end)
I also tried the way from the wiki, and it still didn't work. (i already got rid of the code but it was essentially this with a remoteevent)
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.R then
print("R was pressed")
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

1 comment
Thank you for this! I was super tried while writing the code I didn't even notice I wrote :FireService. I'm very embarrassed but thankful for your amazing answer!