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

Where do I go to learn UserInputService?

Asked by
funyun 958 Moderation Voter
9 years ago

There's a wiki page for its functions and events and stuff, but there's no walkthrough on how you'd use it like with DataStores. Do people just learn it from other people's code?

0
Sorry. Had to edit my question. What I'm asking for is how people actually use it. funyun 958 — 9y
0
He doesnt want the Class API page.. He wants an explanation unmiss 337 — 9y
0
The UserInputService triggers events which tell you code WHEN to do something. You can use those events to get a DataStore when it's triggered. GoldenPhysics 474 — 9y

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

The UserInputService is a Service that allows you to do pretty much anything when it comes to the User interacting with the game.

It tracks whenever a player clicks the mouse, and when they press keys. It can also be used with mobile devices for when the screen is touched or swiped. Here's an example of one of the scripts that I've used with it:

Plr=game.Players.LocalPlayer
Mouse=Plr:GetMouse()

UIS=game:GetService("UserInputService")

UIS.InputBegan:connect(function(Type)
    if Type.UserInputType==Enum.UserInputType.MouseButton1 or  Type.UserInputType==Enum.UserInputType.MouseButton2 then
        print("Player Clicked")
    elseif if Type.UserInputType==Enum.UserInputType.MouseWheel then
        print("Mouse Wheel Moved")
    elseif if Type.UserInputType==Enum.UserInputType.MouseMovement then
        print("Mouse Moving")
    elseif if Type.UserInputType==Enum.UserInputType.Keyboard then
        local Keys=UserInputType:GetKeysPressed()
        for i=1,#Keys do
            print(Keys[i].." is being pressed") --Prints every key that is being pressed
        end
    end
end)

These are only a few examples of what it can be used for however. It can also be used to do things from telling how the users device is rotated, to telling whether or not the user has the window open on their screen.

I can't list them all here, so check out this page to learn more.


If you have any further questions, please leave a comment below. Hope I helped :P

Ad

Answer this question