Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Where do I go to learn UserInputService?

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?

4 comments

0

Sorry. Had to edit my question. What I'm asking for is how people actually use it.

0

He doesnt want the Class API page.. He wants an explanation

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.

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.