Draft preview · this lesson is still being technically validated. Browser experiments and reference material remain available; trusted completion is enabled after publication.

← Back to journey

Offer touch, keyboard and gamepad actions

v2 · Activity 1 of 0 · input · contextactionservice · accessibility · 28 min Requires Roblox Studio

Chapter outline
Loading draft…
Mini-mission

ContextActionService binds a named action to input choices. The callback receives actionName, inputState and inputObject. React on Begin so a press does not toggle again on release.

createTouchButton=true creates a touch alternative. Give it a clear title and position. Also retain an ordinary visible GUI button as a discoverable action.

Your task

Toggle QuestPanel with Q, gamepad ButtonY, a labeled touch action, and QuestButton.Activated. Bind once and unbind when the GUI is destroyed.

Interface: Complete the documented Studio hierarchy and self-check the behavior outside the browser.

InputExpected
Syntax in this activity

New syntax: input, contextactionservice, accessibility

Earlier ideas used here
  • ui-state
  • rendering
Self-check rubric
  • Keyboard press/release performs one transition.
  • Touch has a readable reachable alternative.
  • Gamepad can use the binding and select the ordinary button.
  • Destroying the GUI releases ToggleQuest.

Your explanation is a self-check. Exact wording is not automatically graded.

Self-checked Studio exercise. A saved checklist records your own review; no uploaded place file or screenshot is executed here.

Build this hierarchy

StarterGui/QuestInputGui (ScreenGui)
  QuestPanel (Frame)
  QuestButton (TextButton, Text=Quests, Selectable=true)
  QuestInput (LocalScript)
  1. Create visible, readable panel and button objects.
  2. Use Studio device emulation and a gamepad if available.
StarterGui/QuestInputGui/QuestInput.client.luau

Main guided reference implementation; use the hierarchy’s stated Script or ModuleScript type.

local ContextActionService = game:GetService("ContextActionService")
local gui = script.Parent
local panel = gui:WaitForChild("QuestPanel")
local button = gui:WaitForChild("QuestButton")
local function toggle() panel.Visible = not panel.Visible end
local function onAction(_, state)
    if state ~= Enum.UserInputState.Begin then return Enum.ContextActionResult.Pass end
    toggle()
    return Enum.ContextActionResult.Sink
end
ContextActionService:BindAction("ToggleQuest", onAction, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonY)
ContextActionService:SetTitle("ToggleQuest", "Quests")
ContextActionService:SetPosition("ToggleQuest", UDim2.new(1,-160,1,-160))
local connection = button.Activated:Connect(toggle)
gui.Destroying:Connect(function()
    ContextActionService:UnbindAction("ToggleQuest")
    connection:Disconnect()
end)

Expected output

  • Q, ButtonY, touch action and visible button each toggle the same panel once.

Studio assessment checklist

Multiplayer tests

  1. Run a local server and at least one client; compare server and client context where the activity uses both.
Troubleshooting and production considerations

Conflicting action names can replace bindings; use a scoped name in a larger project.

A press may be consumed by higher-priority contexts; inspect action bindings before adding duplicate handlers.

This is a bounded learning lab. It has not been executed in an approved Roblox Studio environment by this website.

A checked checklist records your own review, not automated project competence or a community verification.

Your goal

Toggle QuestPanel with Q, gamepad ButtonY, a labeled touch action, and QuestButton.Activated. Bind once and unbind when the GUI is destroyed.

Reset starter

Replace this code with the starter? Download your draft to keep a copy.

Code

Studio source file
Luau keyword highlighting · Ctrl/⌘ + Enter: Run · Esc: leave editor

Edit and run these files in Roblox Studio. This browser has no Roblox services, physics, or replication.

Your output will appear here.

Ready