Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can i have some more help on userInputService?

Asked by
Jumbuu 110
8 years ago

im having trouble understanding what i can do with it and the differen functions/events

2 answers

Log in to vote
2
Answered by 8 years ago

UserInputService is a great replacement for the old technique of getting input from the users keyboard via the PlayerMouse object.


UserInputService is comprised of two kinds of input enumerations:

1: UserInputType - This contains information regarding the PlayerMouse

2: KeyCode - This contains information regarding the keyboard

You can compare these values with what kind of input the user actually gave to the computer. This is done using the equal to operator ( == ) and an if statement, then carrying on with what happens if the statement returns true. Here's an example:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(Input)
    local MouseInput = Input.UserInputType -- Get all mouse inputs
    local KeyCode = Input.KeyCode -- Get all keyboard inputs

    -- Now compare them with what matches in the Enum library
    -- If A was pressed, then...
    if KeyCode == Enum.KeyCode.A then
        print("A was pressed")

    -- If B was pressed, then...
    elseif KeyCode == Enum.KeyCode.B then
        print("B was pressed")

    -- If the left clicker was clicked (on the mouse) then...
    elseif MouseInput == Enum.UserInputType.MouseButton1 then
        print("Mouse was left clicked")
    end
end)

Here's a list of all the available KeyCodes you can use: http://wiki.roblox.com/index.php?title=API:Enum/KeyCode

Here's a list of all the available UserInputTypes (or, mouse inputs) you can use: http://wiki.roblox.com/index.php?title=API:Enum/UserInputType

I also have a module that makes working with UserInputService a bit easier. You can find it here: https://www.roblox.com/Custom-events-library-Create-or-modify-events-item?id=398814042

If you have any questions about the module, I have a video explaining how it works here: https://www.youtube.com/watch?v=9bggLpCFMOg

Hope that helped, let me know if you have any questions.

0
All I can do is give this answer 1000/10 thank you so much Jumbuu 110 — 8y
Ad
Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

The Wiki post has all the events/functions listed, and most of them have an example.

Answer this question