We use cookies on this site to enhance your user experience

Avatar Context Menu

Avatar Context Menu

Jan 18 2019, 6:44 PM PST 5 min

The Avatar Context Menu (ACM) is an opt-in feature that allows easy player-to-player social interaction. When the ACM is enabled, a player can walk up to another player and tap/click on them to open a window with several options. The player can send a friend request, begin a private chat, or wave. This menu may be customized with custom actions, such as initiating trades, battles, and more.

A player opens the Avatar Context Menu interface in Lumber Tycoon 2

Enabling the Avatar Context Menu

The Avatar Context Menu isn’t ideal for all games, so it must be enabled using the StarterGui/SetCore|StarterGui:SetCore() option "SetAvatarContextMenuEnabled" in a LocalScript. The ACM is best used in games where there is no pre-defined behavior for clicking/tapping on other players.

-- Run in a LocalScript, ideally within "StarterPlayerScripts"
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCore("SetAvatarContextMenuEnabled", true)

Avatar Context Menu in Action

Opening the Menu

In games where this feature is enabled, clicking or tapping a character will open the ACM. By default, the menu will have the following options:

Menu Option Enum* Description
Friend Friend Sends a friend request to the selected player.
Chat Chat Opens a private conversation with the selected player in the in-game chat.
Wave Emote Currently initiates a wave animation to the selected player. The list of available emotes will be expanded upon in the near future.
* The /enum/AvatarContextMenuOption|AvatarContextMenuOption enum value used when adding/removing these default options

Character Selection Carousel

Once the ACM is open, the player can swipe and click/tap to select other Player|Players on the character selection carousel. Characters are sorted based on distance to the selected character (ascending). The menu only updates when first opened, and wraps around from beginning to end.

The character that’s currently selected in the carousel is the one being interacted with. A player could quickly swap between characters using the selection carousel to Add Friend, Chat, etc. with multiple different characters.

Closing the Menu

The ACM can be closed by clicking the in the top-right corner (or tap somewhere outside it). After closing, controls are returned to the player. For gamepad controllers, the “B” button closes the menu.

Customizing the Avatar Context Menu

Once enabled, game-specific actions can be added to the menu. For example, a game might allow for trade requests, add-to-party options, or other special interactions.

Adding Custom Actions

The following example shows how add a custom action to the Avatar Context Menu.

local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local player = Players.LocalPlayer

-- Connect a function to a "BindableEvent"
local bindableEvent = Instance.new("BindableEvent")
local function onCustomACMAction(targetPlayer)
	-- At this point, you could call InvokeServer() on a RemoteFunction to alert the server of the selection
	print("ACM event selected by " .. player.Name .. " on " .. targetPlayer.Name)

-- Add the ACM option using SetCore() with "AddAvatarContextMenuOption"
local options = {"Custom ACM Action", bindableEvent}
StarterGui:SetCore("AddAvatarContextMenuOption", options)

Here’s a broad overview of this code sample:

  1. The first few lines get the necessary game services such as Players and StarterGui.
  2. The next block defines a function, onCustomACMAction(), and connects it to a BindableEvent.
  3. The final block calls StarterGui/SetCore|StarterGui:SetCore() with the option "AddAvatarContextMenuOption", providing a table with the name of the action and the BindableEvent.

Removing Actions

To remove a custom action which you added to the Avatar Context Menu, call StarterGui/SetCore|StarterGui:SetCore() with the option "RemoveAvatarContextMenuOption" and the name of the action (the first value in the options table as shown on line 14 above).

StarterGui:SetCore("RemoveAvatarContextMenuOption", "Custom ACM Action")

Additionally, any default option may be removed by using Enum/AvatarContextMenuOption enums:

-- Remove the "Friend" option (you can also choose "Chat" or "Emote")
StarterGui:SetCore("RemoveAvatarContextMenuOption", Enum.AvatarContextMenuOption.Friend)
  • gui
  • context