The UI namespace contains a set of class functions allowing you to get information about a Player's display and push information to their HUD. Most functions require the script to be inside a ClientContext and execute for the local Player.
|Class Function Name||Return Type||Description||Tags|
| || ||Shows a quick text on screen that tracks its position relative to a world position. The last parameter is an optional table containing additional parameters: duration (number) - How long the text should remain on the screen. Default duration is 0.5 seconds; color (Color) - The color of the Text. Default is white; font (string) - Asset ID for the font to use; isBig (boolean) - When true, larger text is used.||Client-Only|
| || ||Local player sees an arrow pointing towards some damage source. Lasts for 5 seconds.||Client-Only|
| || ||Local player sees an arrow pointing towards some CoreObject. Multiple calls with the same CoreObject reuse the same UI indicator, but refreshes its duration.||Client-Only|
| || ||Local player sees an arrow pointing towards some other Player. Multiple calls with the same Player reuse the same UI indicator, but refreshes its duration. The arrow points to where the source was at the moment ||Client-Only|
| || ||Returns a Vector2 with the ||None|
| || ||Calculates the location that worldPosition appears on the screen. Returns a Vector2 with the ||None|
| || ||Returns a Vector2 with the size of the Player's screen in the ||None|
| || ||Draws a message on the corner of the screen. Second optional Color parameter can change the color from the default white.||Client-Only|
| || ||Returns whether the cursor is visible.||Client-Only|
| || ||Sets whether the cursor is visible.||Client-Only|
| || ||Returns whether to lock cursor in viewport.||Client-Only|
| || ||Sets whether to lock cursor in viewport.||Client-Only|
| || ||Returns whether the cursor can interact with UI elements like buttons.||Client-Only|
| || ||Sets whether the cursor can interact with UI elements like buttons.||Client-Only|
| || ||Check if reticle is visible.||Client-Only|
| || ||Shows or hides the reticle for the Player.||Client-Only|
| || ||Return hit result from local client's view in direction of the Projected cursor position. Meant for client-side use only, for Ability cast, please use ||Client-Only|
| || ||Return intersection from local client's camera direction to given plane, specified by point on plane and optionally its normal. Meant for client-side use only. Example usage: ||Client-Only|
| || ||Sets whether the rewards dialog is visible, and optionally which tab is active.||Client-Only|
| || ||Returns whether the rewards dialog is currently visible.||Client-Only|
| || ||Sets whether the social menu is enabled.||Client-Only|
| || ||Returns whether the social menu is enabled.||Client-Only|
| || ||Returns the currently active core modal, or nil if none is active.||Client-Only|
|Event Name||Return Type||Description||Tags|
| ||< ||Fired when the local player pauses the game or opens one of the built-in modal dialogs, such as the emote or mount picker. The modal parameter will be ||Client-Only|
GetScreenPosition method is a powerful function that does a lot of behind the scenes math to convert any 3D point in the game world into a 2D screen coordinate. This script will use the
GetScreenPosition method to cause a UI Text object to jump to different players and follow each player for 2 second intervals.
Your UI Text object needs to be set to dock in the top-left of the screen for the
GetScreenPosition method to provide accurate 2D coordinates. Your UI Text object should also be a direct child of a UI Container for the
GetScreenPosition method to provide accurate 2D coordinates.
-- Grab the text object local propUIText = script:GetCustomProperty("UIText"):WaitForObject() -- Represents how many seconds are left until the UI Text moves to the next player local timeLeft = 0 -- Determines how long (in seconds) the text hovers above the name of a player local intervalTime = 2 -- Represents which player the UI Text will is currently hovering over local playerIndex = 1 -- Stores a list of players in the game local playerList = Game.GetPlayers() -- Stores the player object that the UI Text should hover above local targetPlayer = nil function Tick(deltaTime) -- Update the "playerList" to reflect any changes to the list of players in the game (players leaving the game or entering the game) playerList = Game.GetPlayers() -- Update the "timeLeft" variable timeLeft = timeLeft - deltaTime -- If "timeLeft" has reached 0 and there are still players in the game, reset the "timeLeft" variable and move the text to the next player if(timeLeft <= 0 and #playerList > 0) then -- Reset the "timeLeft" variable to "intervalTime" number of seconds timeLeft = intervalTime -- Move the "playerIndex" to the next player in the "playerLIst" playerIndex = playerIndex + 1 -- If "playerIndex" is larger than the length of "playerList", reset "playerIndex" to the beginning of "playerList" if(playerIndex > #playerList) then playerIndex = 1 end -- Update the "targetPlayer" variable with the player object located at "playerIndex" position on the "playerList" targetPlayer = playerList[playerIndex] end -- If "targetPlayer" refers to an actual player, update the position of the UI Text to -- be above that player's head if(Object.IsValid(targetPlayer)) then -- Get the position of the player's head by vertically offseting the position of the player local playerHeadPos = targetPlayer:GetWorldPosition() + Vector3.New(0, 0, 120) -- Convert the position of the player's head to 2D coordinates local playerHeadScreenPos = UI.GetScreenPosition(playerHeadPos) -- Change the text of the UI Text to display the name of the "targetPlayer" propUIText.text = targetPlayer.name -- Move the UI Text to the "playerHeadScreenPos" position propUIText.x = playerHeadScreenPos.x propUIText.y = playerHeadScreenPos.y end end
This example shows the basic usage of the reward points UI. It's possible to show the rewards dialog, in either the Quest or Game tabs, by calling
UI.SetRewardsDialogVisible(). With the function
UI.IsRewardsDialogVisible() we can detect when the player closes the dialog.
local PLAYER = Game.GetLocalPlayer() local isDialogOpen = false function Tick() if isDialogOpen and not UI.IsRewardsDialogVisible() then isDialogOpen = false print("Player closed the Reward Points dialog.") end end function OnBindingPressed(player, action) if action == "ability_extra_1" then UI.SetRewardsDialogVisible(true, RewardsDialogTab.REWARD_POINT_GAMES) elseif action == "ability_extra_2" then UI.SetRewardsDialogVisible(true, RewardsDialogTab.QUESTS) end end PLAYER.bindingPressedEvent:Connect(OnBindingPressed)
This client script listens for changes in the local player's modal and prints to the Event Log information about which modal was opened, or if modals were closed.
-- Converts the enum CoreModalType into a string, to make the log more readable function ToStringModaltype(modalType) -- The pause menu opened by pressing the Escape key, or other minor pause states if modalType == CoreModalType.PAUSE_MENU then return "PAUSE" end -- Popup when the player is choosing a character if modalType == CoreModalType.CHARACTER_PICKER then return "CHARACTER PICKER" end -- Popup when the player is choosing a mount if modalType == CoreModalType.MOUNT_PICKER then return "MOUNT PICKER" end -- Popup when the player is choosing an emote if modalType == CoreModalType.EMOTE_PICKER then return "EMOTE PICKER" end -- Popup when the player is inspecting another player for social actions if modalType == CoreModalType.SOCIAL_MENU then return "SOCIAL MENU" end -- Fallback, future-proof return "???" .. tostring(modalType) end function OnModalChanged(modalType) if modalType ~= nil then print("Modal changed to: " .. ToStringModaltype(modalType)) else print("Closed modal.") end end UI.coreModalChangedEvent:Connect(OnModalChanged)
See also: CoreModalType