Draft preview · this lesson is still being technically validated. Browser experiments and reference material remain available; trusted completion is enabled after publication.
v2 · Activity 4 of 4 · input · contextactionservice · accessibility · 28 min Requires Roblox Studio
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.
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.
| Input | Expected |
|---|
local function onAction(_, state)
if state ~= Enum.UserInputState.Begin then return Enum.ContextActionResult.Pass end
print("Action pressed")
return Enum.ContextActionResult.Sink
endFiltering input state prevents duplicate Begin/End behavior.
New syntax: input, contextactionservice, accessibility
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.
StarterGui/QuestInputGui (ScreenGui) QuestPanel (Frame) QuestButton (TextButton, Text=Quests, Selectable=true) QuestInput (LocalScript)
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)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.
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.
Return Pass when an input should continue to other handlers and Sink when this interface intentionally consumes it. Unbind your action on teardown so an old screen does not keep intercepting input.
Replace this code with the starter? Download your draft to keep a copy.
Edit and run these files in Roblox Studio. This browser has no Roblox services, physics, or replication.
Your output will appear here.
Sign in with RoCreators to save private progress across devices. Community verification is separate.