UserInputService for Roblox

This needs to go into a local script inside of the StarterPlayerScripts, This gets your Keyboard & Mouse input
 avatar
S0ftFemBunny
lua
24 days ago
796 B
8
Indexable
-- Certain Key
UserInputService = game:GetService('UserInputService')

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.E then --waits until E is pressed
        print("E has been pressed")
    end
end)


-- Any Key
UserInputService = game:GetService('UserInputService')

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    print(input.UserInputType) -- Detects if any key is pressed
end)


-- Print certain and any key
UserInputService = game:GetService('UserInputService')

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.E then
        print("E has been pressed") -- waits until key is pressed to print
    end
    print(input.UserInputType) --prints any key
end)
Editor is loading...
Leave a Comment