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

Make a button work across inputs

v2 · Activity 1 of 0 · button-events · activated · 28 min Requires Roblox Studio

Chapter outline
Loading draft…
Mini-mission

GuiButton.Activated is the cross-input activation event. It supports mouse, touch and gamepad selection activation. It is preferable here to a mouse-only assumption.

A client-side sound preference is local presentation state. Toggling it does not require granting authoritative rewards. This exercise does not play sound; off remains the default.

Your task

Make SoundButton start at Sound: off. Toggle a local soundEnabled boolean and the label with Activated. Use a readable touch-sized button.

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

InputExpected
Syntax in this activity

New syntax: button-events, activated

Earlier ideas used here
  • screengui
  • layout
Self-check rubric
  • Mouse activation toggles once.
  • Touch emulation toggles the same behavior.
  • Gamepad selection and activation can reach the button.

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/SettingsGui (ScreenGui)
  SoundButton (TextButton)
  SoundController (LocalScript)
  1. Create the stated hierarchy and place the button near screen center.
  2. Set a readable background/text contrast in Properties.
StarterGui/SettingsGui/SoundController.client.luau

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

local button = script.Parent:WaitForChild("SoundButton")
local soundEnabled = false
button.Size = UDim2.fromOffset(200,52)
button.TextSize = 20
button.Selectable = true
local function render() button.Text = soundEnabled and "Sound: on" or "Sound: off" end
button.Activated:Connect(function() soundEnabled = not soundEnabled; render() end)
render()

Expected output

  • The initial label is Sound: off.
  • Each activation alternates on and off.

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

A GUI object covering the button can intercept input; inspect overlap and visibility.

Do not bind both mouse-only and Activated to the same toggle unless you prevent duplicate activation.

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

Make SoundButton start at Sound: off. Toggle a local soundEnabled boolean and the label with Activated. Use a readable touch-sized button.

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