From c4231d77b9fa14e735e5aaeb619f8a4aa3b66035 Mon Sep 17 00:00:00 2001 From: "rbx-open-source-docs[bot]" <138828531+rbx-open-source-docs[bot]@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:29:02 +0000 Subject: [PATCH] update Open Source Docs from Roblox internal teams --- content/common/navigation/cloud/guides.yaml | 2 + content/common/navigation/engine/guides.yaml | 20 +- content/en-us/art/accessories/index.md | 6 +- .../ScreenGui/Top-Bar-Safe-Area-Collapsed.png | 3 + .../ScreenGui/Top-Bar-Safe-Area-Expanded.png | 3 + .../open-cloud-nodejs-sample-oauth2-main.zip | 3 + content/en-us/avatar/tutorials.md | 2 +- .../en-us/cloud/open-cloud/oauth2-sample.md | 79 ++++ content/en-us/cloud/reference/oauth2.md | 27 +- content/en-us/cloud/reference/patterns.md | 2 +- .../en-us/input/customizing-mouse-icons.md | 52 --- content/en-us/input/gamepad.md | 4 +- content/en-us/input/index.md | 6 +- content/en-us/input/mobile.md | 8 +- content/en-us/input/mouse-and-keyboard.md | 359 +++++++++--------- content/en-us/navigation/navigation.json | 6 +- .../nominating-for-the-discover-page.md | 30 +- .../publishing/creator-marketplace.md | 2 +- .../en-us/resources/modules/merch-booth.md | 2 +- content/en-us/sound/objects.md | 2 +- content/en-us/studio/home-tab.md | 2 +- content/en-us/ui/automatic-sizing.md | 2 +- content/en-us/ui/buttons.md | 14 +- content/en-us/ui/cross-platform-design.md | 2 +- content/en-us/ui/drag-detectors.md | 4 - content/en-us/ui/index.md | 33 +- content/en-us/ui/labels.md | 8 +- content/en-us/ui/on-screen-containers.md | 5 +- content/en-us/ui/{text.md => text-input.md} | 12 +- 29 files changed, 357 insertions(+), 343 deletions(-) create mode 100644 content/en-us/assets/engine-api/classes/ScreenGui/Top-Bar-Safe-Area-Collapsed.png create mode 100644 content/en-us/assets/engine-api/classes/ScreenGui/Top-Bar-Safe-Area-Expanded.png create mode 100644 content/en-us/assets/open-cloud/open-cloud-nodejs-sample-oauth2-main.zip create mode 100644 content/en-us/cloud/open-cloud/oauth2-sample.md delete mode 100644 content/en-us/input/customizing-mouse-icons.md rename content/en-us/ui/{text.md => text-input.md} (90%) diff --git a/content/common/navigation/cloud/guides.yaml b/content/common/navigation/cloud/guides.yaml index 65a7c5864..03eef943a 100644 --- a/content/common/navigation/cloud/guides.yaml +++ b/content/common/navigation/cloud/guides.yaml @@ -11,6 +11,8 @@ navigation: path: /cloud/open-cloud/oauth2-registration - title: Implementation path: /cloud/open-cloud/oauth2-develop + - title: Sample App + path: /cloud/open-cloud/oauth2-sample - title: API Keys path: /cloud/open-cloud/api-keys - heading: V2 Resources (Beta) diff --git a/content/common/navigation/engine/guides.yaml b/content/common/navigation/engine/guides.yaml index 7b76d628c..7b439a28a 100644 --- a/content/common/navigation/engine/guides.yaml +++ b/content/common/navigation/engine/guides.yaml @@ -298,12 +298,8 @@ navigation: - title: Overview path: /input/ - title: Mouse and Keyboard - section: - - title: Overview - path: /input/mouse-and-keyboard - - title: Customizing Mouse Icons - path: /input/customizing-mouse-icons - - title: Mobile Input + path: /input/mouse-and-keyboard + - title: Mobile path: /input/mobile - title: Gamepad path: /input/gamepad @@ -338,7 +334,11 @@ navigation: - title: Buttons path: /ui/buttons - title: Text Input - path: /ui/text + path: /ui/text-input + - title: Proximity Prompts + path: /ui/proximity-prompts + - title: Drag Detectors + path: /ui/drag-detectors - title: Video Assets path: /ui/video-assets - title: Layout and Design @@ -357,10 +357,6 @@ navigation: path: /ui/cross-platform-design - title: UI Animation path: /ui/animation - - title: Proximity Prompts - path: /ui/proximity-prompts - - title: Drag Detectors - path: /ui/drag-detectors - title: Text Filtering path: /ui/text-filtering - title: Loading Screens @@ -383,7 +379,6 @@ navigation: path: /animation/inverse-kinematics - title: Using Animations path: /animation/using - - title: Chat section: - title: Spatial Voice @@ -398,7 +393,6 @@ navigation: path: /chat/bubble-chat - title: Migrating to In-Experience Text Chat path: /chat/migrate-to-in-experience-text-chat - - title: Cloud Services section: - title: Data Stores diff --git a/content/en-us/art/accessories/index.md b/content/en-us/art/accessories/index.md index 623cccc04..d0348ec85 100644 --- a/content/en-us/art/accessories/index.md +++ b/content/en-us/art/accessories/index.md @@ -19,7 +19,9 @@ Custom accessories are first created in 3D modeling programs, such as [Blender]( - A basic background with 3D modeling tools such as [Blender](https://www.blender.org/) or [Maya](https://www.autodesk.com/products/maya/overview). - An understanding of the [components that make up an accessory](#components-of-an-accessory). - An understanding of the general [accessory creation process](#creation-process). -- Review the [clothing creation tutorial](../../art/accessories/creating/index.md), a step-by-step process of creating your own avatar-ready clothing from scratch in Blender. +- Review Roblox's official tutorials to create your own accessories: + - [Rigid accessory creation tutorial](../../art/accessories/creating-rigid/index.md) - covers each process required for converting a 3D model to a rigid accessory and publishing it to the Marketplace. + - [Clothing creation tutorial](../../art/accessories/creating/index.md) - a step-by-step process of creating your own avatar-ready clothing from scratch in Blender. - [Additional tools, resources, and guides](#resources) provided by Roblox to standardize and expedite the creation process. ### Components of an Accessory @@ -116,7 +118,7 @@ If you are interested in specific avatar creation topics, use the following tabl Tutorials - [Basic Clothing Creation](../../art/accessories/creating/index.md) + [Rigid Accessory Creation](../../art/accessories/creating-rigid/index.md)

[Basic Clothing Creation](../../art/accessories/creating/index.md) Reference Files diff --git a/content/en-us/assets/engine-api/classes/ScreenGui/Top-Bar-Safe-Area-Collapsed.png b/content/en-us/assets/engine-api/classes/ScreenGui/Top-Bar-Safe-Area-Collapsed.png new file mode 100644 index 000000000..e018d7fa5 --- /dev/null +++ b/content/en-us/assets/engine-api/classes/ScreenGui/Top-Bar-Safe-Area-Collapsed.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d6c3dadb08b5aca0b7a9c45a3ffa36a7a418ed0ef3fb753ce27200a577456be5 +size 312309 diff --git a/content/en-us/assets/engine-api/classes/ScreenGui/Top-Bar-Safe-Area-Expanded.png b/content/en-us/assets/engine-api/classes/ScreenGui/Top-Bar-Safe-Area-Expanded.png new file mode 100644 index 000000000..4eee461ae --- /dev/null +++ b/content/en-us/assets/engine-api/classes/ScreenGui/Top-Bar-Safe-Area-Expanded.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47315a3a8f9fbd69a7352f29f5f093f17dee01d520d5fe98554aeda60e810204 +size 310157 diff --git a/content/en-us/assets/open-cloud/open-cloud-nodejs-sample-oauth2-main.zip b/content/en-us/assets/open-cloud/open-cloud-nodejs-sample-oauth2-main.zip new file mode 100644 index 000000000..cdaae2189 --- /dev/null +++ b/content/en-us/assets/open-cloud/open-cloud-nodejs-sample-oauth2-main.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fcab957f4e26c6c56d26ade71f00873e8fd58f063208d97fb9354c027b4b1b6e +size 11787 diff --git a/content/en-us/avatar/tutorials.md b/content/en-us/avatar/tutorials.md index 7f82ec99d..aa21dc95d 100644 --- a/content/en-us/avatar/tutorials.md +++ b/content/en-us/avatar/tutorials.md @@ -113,7 +113,7 @@ style={{position: "relative"}}> - + + + +
+ +After downloading the `.zip` file, extract it to its own folder. + +## Registering the App + +The first step to setting up the app is to [register it on the Roblox website](oauth2-registration.md) and copy the client ID and secret somewhere safe. Then follow the standard registration steps with these settings: + +1. Under **Permissions**, add the `openid` and `profile` scopes. +1. Under **Redirect URLs**, add the `http://localhost:3000/oauth/callback` redirect. If you want to use a non-default port for your app, specify it here. + +## Setting Environment Variables + +Rather than storing them in code (not recommended), the app uses environment variables for your client ID and secret. The process for adding environment variables differs by operating system. + +On Windows, run the following PowerShell commands: + +```powershell +$env:ROBLOX_CLIENT_ID='your_client_id_here' +$env:ROBLOX_CLIENT_SECRET='your_client_secret_here' +$env:ROBLOX_PORT=3000 # Optional. Default is 3000. +``` + +On macOS and most Linux distributions, run these commands at the terminal: + +```bash +export ROBLOX_CLIENT_ID=your_client_id_here +export ROBLOX_CLIENT_SECRET=your_client_secret_here +export ROBLOX_PORT=3000 # Optional. Default is 3000. +``` + +If you specified a non-default port in the redirect URL when registering your app, be sure to add the `ROBLOX_PORT` variable. + + +These commands only set environment variables for the duration of your terminal session. If you want to load these variables every time you open a new terminal window, add the commands to your shell configuration file, such as `.zshrc` or `.bashrc`. Many hosting services have features to help you add environment variables to your servers. + + +## Installing Dependencies + +The app has a handful of dependencies, visible in `package.json`. To install them, run: + +```bash +npm ci +``` + +## Running the App + +To start the app, run: + +```bash +npm start +``` + +Then navigate to `http://localhost:3000` (or your non-default port) in a web browser. + +The app immediately redirects you to the Roblox login screen, at which point you can log in, verify the permissions that the app is requesting, and click **CONFIRM AND GIVE ACCESS**. + +Roblox then redirects you back to `localhost`, where you can see that the app now displays some minimal user information and a link back to your profile on Roblox. + +### About the App + +In broad strokes, `index.js` performs the following operations: + +1. Starts a new web server using `express`. +1. Retrieves the Roblox OpenID Connect (OIDC) configuration, which includes endpoints for authorization, user information, etc. For more information about these endpoints, see [OAuth 2.0 Authentication](../reference/oauth2.md). +1. Creates a new Open ID client using `openid-client` and your stored credentials. This client dramatically simplifies the process of properly forming and sending HTTP requests to the various OAuth 2.0 endpoints. +1. Defines the various routes for the app, including redirects for the login and logout flows and the OAuth 2.0 callback. +1. After a successful login, stores the various tokens as cookies, along with some minimal user information that it displays as HTML with help from `getHomeHtml.js`. diff --git a/content/en-us/cloud/reference/oauth2.md b/content/en-us/cloud/reference/oauth2.md index 32807d1cb..3c2400ee6 100644 --- a/content/en-us/cloud/reference/oauth2.md +++ b/content/en-us/cloud/reference/oauth2.md @@ -4,17 +4,18 @@ description: Describes how to make authenticated calls to Open Cloud with API ke --- - OAuth 2.0 authentication is a beta feature that might be subject to change for - future releases. All Open Cloud endpoints also support [API Key authentication](../open-cloud/api-keys.md). +OAuth 2.0 authentication is a beta feature that might be subject to change for +future releases. All Open Cloud endpoints also support +[API key authentication](../open-cloud/api-keys.md). -For complete implementation guides and information -on OAuth 2.0, see the [OAuth 2.0 Overview](../open-cloud/oauth2-overview.md). +For complete implementation guides and information on OAuth 2.0, including a +sample app, see the [OAuth 2.0 Overview](../open-cloud/oauth2-overview.md). This document describes endpoints that you call to implement the OAuth 2.0 -authorization code flow as well as other endpoints useful for implementing +authorization code flow, as well as other endpoints useful for implementing authentication in your apps. ```http title="Base URL" @@ -316,14 +317,14 @@ curl --location --request GET 'https://apis.roblox.com/oauth/v1/userinfo' \ You can use the `sub` value to uniquely identify the user. Users can change their Roblox username and display name, so don't use them as unique identifiers to refer to users on your app. -| Claim | Description | -| ------------------ | ----------------------------------------- | -| sub | Roblox user ID. | -| name | Roblox display name. | -| nickname | Roblox display name. | -| preferred_username | Roblox username. | -| created_at | Creation time of the Roblox account as a Unix timestamp. | -| profile | Roblox account profile URL. | +| Claim | Description | +| ------------------ | ----------------------------------------------------------------------------------------------------------------------- | +| sub | Roblox user ID. | +| name | Roblox display name. | +| nickname | Roblox display name. | +| preferred_username | Roblox username. | +| created_at | Creation time of the Roblox account as a Unix timestamp. | +| profile | Roblox account profile URL. | | picture | Roblox avatar headshot image. Can be null if the avatar headshot image hasn't yet been generated or has been moderated. | ```json title="Example User with Profile Scope" diff --git a/content/en-us/cloud/reference/patterns.md b/content/en-us/cloud/reference/patterns.md index e9d885f98..34e4d3e75 100644 --- a/content/en-us/cloud/reference/patterns.md +++ b/content/en-us/cloud/reference/patterns.md @@ -64,7 +64,7 @@ either user or role in the following formats: - **Role filter**: `filter="role == 'groups/123/roles/7920705'"` If you specify the wildcard character for the group ID, you must filter -memberships by user (up to 5) in the following format: +memberships by user (up to 50) in the following format: - **User filter**: `filter="user in ['users/1', 'users/156', 'users/9876543210', ...]"` diff --git a/content/en-us/input/customizing-mouse-icons.md b/content/en-us/input/customizing-mouse-icons.md deleted file mode 100644 index 29d2a78b7..000000000 --- a/content/en-us/input/customizing-mouse-icons.md +++ /dev/null @@ -1,52 +0,0 @@ ---- -title: Customizing Mouse Icons -description: Explains the process of customizing the appearance and behavior of a user's mouse icon within your experience. ---- - -You can customize the appearance and behavior of a user's mouse icon within your experience to create a cohesive style across all of your UI elements. This includes temporarily changing the user's mouse icon in specific circumstances, such as clicking a button or while the mouse hovers over another user. - -## Changing Mouse Icons - -You can change the user's mouse icon in a `Class.LocalScript` by setting the `Class.UserInputService.MouseIcon|MouseIcon` property in `Class.UserInputService` to a custom Roblox asset ID. For example, the following `Class.LocalScript` changes the user's default mouse icon to a black circle with a blue dot in the middle: - -```lua -local UserInputService = game:GetService("UserInputService") -UserInputService.MouseIcon = "rbxassetid://3400146391" -``` - -Because the mouse icon is set in a `Class.LocalScript`, each user can have a different icon, or can have an icon appear in certain situations, such as when an ability is recharging or the mouse is hovering over a hostile target. - -## Hiding Mouse Icons - -You can hide the user's mouse icon by setting the `Class.UserInputService.MouseIconEnabled` to `false` in a `Class.LocalScript`. For example, the following code switches the mouse icon from visible to invisible and back every two seconds: - -```lua -local UserInputService = game:GetService("UserInputService") - -while true do - task.wait(2) - UserInputService.MouseIconEnabled = false - task.wait(2) - UserInputService.MouseIconEnabled = true -end -``` - -## Locking Mouse Icon Positions - -You can lock the mouse icon position to the screen using `Class.UserInputService.MouseBehavior` with a value of `Enum.MouseBehavior|MouseBehavior.LockCurrentPosition` or `Enum.MouseBehavior|MouseBehavior.LockCenter`. When you set this property back to `Enum.MouseBehavior|MouseBehavior.Default`, the mouse icon unlocks and can move anywhere on the screen again. - -If a user's mouse icon is locked in a position, `Class.UserInputService.InputChanged` still fires when the user moves the mouse, passing in the distance the mouse has moved. For example, the following code sample locks the user's mouse icon after one second, then Studio prints the mouse delta whenever the user moves their mouse: - -```lua -local UserInputService = game:GetService("UserInputService") - -task.wait(1) - -UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition - -UserInputService.InputChanged:Connect(function(inputObject) - if inputObject.UserInputType == Enum.UserInputType.MouseMovement then - print("Mouse delta is (" .. tostring(inputObject.Delta.X) .. ", " .. tostring(inputObject.Delta.Y) .. ")") - end -end) -``` diff --git a/content/en-us/input/gamepad.md b/content/en-us/input/gamepad.md index 5fbc29337..c7bcf79ab 100644 --- a/content/en-us/input/gamepad.md +++ b/content/en-us/input/gamepad.md @@ -1,5 +1,5 @@ --- -title: Gamepad +title: Gamepad Input description: Explains how to accept input from USB gamepads, such as Xbox and PlayStation controllers. --- @@ -84,7 +84,7 @@ There are three ways to receive input from a gamepad: ### ContextActionService -You can use `Class.ContextActionService` for binding controls to both gamepads and other input sources such as [mobile touchscreen buttons](../input/mobile.md#adding-mobile-buttons) or binding multiple functions to a single button input on any device. For example, use `Class.ContextActionService` to bind an OpenSpellBook action to the right trigger (R2) on a gamepad and the B key on a keyboard in one function. +You can use `Class.ContextActionService` for binding controls to both gamepads and other input sources such as [mobile touchscreen buttons](../input/mobile.md) or binding multiple functions to a single button input on any device. For example, use `Class.ContextActionService` to bind an OpenSpellBook action to the right trigger (R2) on a gamepad and the B key on a keyboard in one function. Use the following code sample to bind an OpenSpellBook action to the gamepad's R2 button and the B key on the keyboard: diff --git a/content/en-us/input/index.md b/content/en-us/input/index.md index 4ae1acd89..10f75b8ea 100644 --- a/content/en-us/input/index.md +++ b/content/en-us/input/index.md @@ -21,7 +21,7 @@ Once you're comfortable with testing and developing your inputs on mouse and keyboard, make your experience compatible with multiple platforms by setting up mobile and gamepad inputs. -See [Mouse and Keyboard](../input/mouse-and-keyboard.md) for more +See [Mouse and Keyboard Input](../input/mouse-and-keyboard.md) for more information on setting up your first custom inputs. ## Mobile @@ -34,7 +34,7 @@ You can bind a single action to a traditional PC input and create an on-screen button for touchscreen devices. You can also dynamically update input behavior so that inputs trigger certain actions only in certain contexts. -See [Mobile](../input/mobile.md) for more information on creating +See [Mobile Input](../input/mobile.md) for more information on creating setting up cross-platform and dynamic inputs. ## Gamepad @@ -43,7 +43,7 @@ Roblox accepts input from USB gamepads such as Xbox and Playstation controllers. Gamepads require additional steps to detect and verify connected gamepads before binding controller inputs to actions. -See [Gamepad](../input/gamepad.md) for more information on setting up +See [Gamepad Input](../input/gamepad.md) for more information on setting up gamepad inputs for your experience. ## Customizing the Camera diff --git a/content/en-us/input/mobile.md b/content/en-us/input/mobile.md index 0fd589c2a..91a56a5cd 100644 --- a/content/en-us/input/mobile.md +++ b/content/en-us/input/mobile.md @@ -1,9 +1,9 @@ --- -title: Mobile +title: Mobile Input description: Explains Roblox support for mobile devices. --- -Over half of all Roblox sessions are played on mobile devices so it is important to consider cross-platform accessibility when designing your experience for a wide audience. You should aim to create an ideal cross-platform experience that supports a variety of input devices, including [mouse and keyboard inputs](./mouse-and-keyboard.md) and [gamepad](./gamepad.md). +Over half of all Roblox sessions are played on mobile devices, so it's important to consider cross-platform accessibility when designing an experience for a wide audience. You should aim to support a variety of input devices, including [mouse and keyboard inputs](../input/mouse-and-keyboard.md) and [gamepad](../input/gamepad.md). When designing a mobile experience, consider the [device orientation](#device-orientation) that you intend user's to use in your experience, then implement your inputs with `Class.ContextActionService` to perform the following mobile-related input tasks: @@ -114,7 +114,7 @@ local playerGUI = Players.LocalPlayer:WaitForChild("PlayerGui") print(playerGUI.CurrentScreenOrientation) ``` -## Movement Modes +## Character Movement Modes Roblox offers several `Class.StarterPlayer` properties you can set to change how users on mobile devices can move through your experience. @@ -267,7 +267,7 @@ Use the following sample code to set a button's position with the `Class.Context ContextActionService:SetPosition("Interact", UDim2.new(1, -70, 0, 10)) ``` -## Context Dependent Inputs +## Context-Dependent Inputs When developing for mobile devices you may often want to change what a single button does based on the context. Since screen space on mobile devices limited, use contextual buttons that perform different actions based on what the character is able to do. diff --git a/content/en-us/input/mouse-and-keyboard.md b/content/en-us/input/mouse-and-keyboard.md index c45e34e2d..8aac5473b 100644 --- a/content/en-us/input/mouse-and-keyboard.md +++ b/content/en-us/input/mouse-and-keyboard.md @@ -1,33 +1,28 @@ --- -title: Mouse and Keyboard +title: Mouse and Keyboard Input description: Explains Roblox support for computer mice and keyboards. --- -You can create unique experiences and provide users with additional functionality with custom inputs. Mouse and keyboards are the most common input devices, so it is important to test and develop your custom input behavior on these devices first. Once you're comfortable with mouse and keyboard inputs, make your experience compatible with multiple platforms by setting up [mobile](../input/mobile.md) and [gamepad](./gamepad.md) inputs. +A large percentage of Roblox sessions are played on devices with a mouse and keyboard, so it's important to properly support these inputs when designing an experience for a wide audience. Once you're comfortable with mouse and keyboard inputs, make your experience compatible across multiple platforms by setting up [mobile](../input/mobile.md) and [gamepad](./gamepad.md) inputs. -For convenience, Roblox sets the most common mouse and keyboard inputs as [default key binds](#roblox-default-bindings). Except for the [reserved bindings](#reserved), you can overwrite these default key binds. +For convenience, Roblox sets the most common mouse and keyboard inputs as [default bindings](#roblox-default-bindings) which, except for the reserved bindings, you can overwrite. -## Mouse Input +## Generic Mouse Input -You can detect mouse position and button clicks using the `Class.UserInputService` to capture [generic mouse inputs](#generic-mouse-input). Roblox also supports legacy mouse input detection with [PlayerMouse](#playermouse) and [ClickDetectors](#clickdetector). - -Mouse inputs also automatically work with [interactive UI elements](../ui/buttons.md#buttons), such as `Class.TextBox|TextBoxes` or `Class.ImageButton|ImageButtons`. - -### Generic Mouse Input - -Like all device inputs, you can capture mouse inputs using `Class.UserInputService`. This service provides a scalable way to capture input changes and device input states for multiple devices at once. +Like all device inputs, you can capture mouse inputs using `Class.UserInputService`. This service provides a scalable way to capture input changes and device input states for multiple devices at once. Roblox also supports legacy mouse input detection with `Class.PlayerMouse` and `Class.ClickDetector|ClickDetectors`. Additionally, you can use `Class.ContextActionService` to handle multiple actions on a single input depending on context, such as using a tool when near a rock, or opening a door when inside a building. See [Context Dependent Inputs](../input/mobile.md#context-dependent-inputs) for information on setting context specific input actions. -To capture mouse clicks and print the position of the mouse to the output, use the following script in a `Class.LocalScript` in `Class.StarterPlayerScripts`: +The following `Class.LocalScript`, when placed in `Class.StarterPlayerScripts`, captures mouse clicks and prints the mouse position to the [Output](../studio/output.md) window: -```lua +```lua title='LocalScript - Output Mouse Click and Position' local UserInputService = game:GetService("UserInputService") -local function onInputEnded(inputObject, gameProcessedEvent) - -- First check if the "gameProcessedEvent" is true +local function onInputEnded(inputObject, processedEvent) + -- First check if the "processedEvent" is true -- This indicates that another script had already processed the input, so this one is ignored - if gameProcessedEvent then return end + if processedEvent then return end + -- Next, check that the input was a mouse event if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then print("Left Mouse button was pressed: ", inputObject.Position) @@ -37,84 +32,22 @@ local function onInputEnded(inputObject, gameProcessedEvent) end UserInputService.InputEnded:Connect(onInputEnded) - ``` -### PlayerMouse +## Generic Keyboard Input -You can also use the legacy `Class.Player:GetMouse()` function to return a `Class.PlayerMouse` object that handles general mouse properties and events. +To access keyboard events, use the `Class.UserInputService.InputEnded` event to track whenever any keystroke or other input ends. Similar to [mouse](#generic-mouse-input) events, this event only works within a `Class.LocalScript`. -Since `Class.Player:GetMouse()` only works when using a `Class.LocalScript`, access `Class.Players.LocalPlayer` to get a reference to the local player and, in `Class.StarterPlayer|StarterPlayer`, parent the script to `Class.StarterPlayerScripts` so that it later runs when copied to `Class.PlayerScripts`. - -Use the following script in a `Class.LocalScript` in `Class.StarterPlayerScripts` to print the mouse coordinates whenever the mouse is clicked: - -```lua -local Players = game:GetService("Players") -local player = Players.LocalPlayer -local mouse = player:GetMouse() - -local function onMouseClick() - print(player.Name .. " clicked at position: " .. tostring(mouse.Hit.Position)) - if mouse.Target then - print("Clicked part: " .. mouse.Target:GetFullName()) - else - print("No part clicked") - end -end - -mouse.Button1Down:Connect(onMouseClick) -``` - -### ClickDetector - -A `Class.ClickDetector` object is a simple way of detecting mouse events on a specific 3D object in an experience. You can add a `Class.ClickDetector` instance to any existing `Class.Model` or `Class.Part` to begin detecting player clicks. - -