Part 7 mini-project: Touch-to-Collect Coin

The last project of the book is a real Roblox Studio scene: a coin that gives the player a point when touched, then disappears. It uses tables, methods, events, and one of the Roblox-specific globals from chapter 31.

This is the first thing in the book that runs inside Roblox Studio, not the terminal. If you have not installed Studio, go back to the end of chapter 31 and do that first.

What to build

When the experience starts:

  1. Each player gets a small leaderstats folder with a value called Coins, starting at 0. The leaderboard at the top of the screen shows this automatically.
  2. A yellow coin (a small Part) sits in the world.
  3. When the player walks into the coin:
    • Their Coins value goes up by 1.
    • The coin disappears.

Files

Two short script files are in projects/06-touch-coin/:

  • player-setup.lua — goes inside a Script in ServerScriptService. It creates leaderstats and Coins for each joining player.
  • coin-touched.lua — goes inside a Script under the Coin Part. It handles the touch.

That folder also has a README.md reminding you of the Studio steps below.

Studio setup, step by step

  1. Open Studio. Use the Baseplate template. A flat grey plate appears.
  2. Insert the Coin Part.
    • In the Explorer panel (top right), right-click Workspace and choose Insert Object -> Part.
    • Rename the new Part to Coin by selecting it and pressing F2, or by double-clicking its name in Explorer.
    • In the Properties panel, set:
      • Anchored = true (so it does not fall)
      • Shape = Cylinder (optional; makes it look like a coin)
      • Size = 2, 0.4, 2
      • BrickColor = Bright yellow
      • Position = roughly 0, 5, 0 (or wherever the player can reach it from the spawn point)
  3. Add a Script to the Coin.
    • Right-click the Coin in Explorer -> Insert Object -> Script.
    • The Script opens in the editor. Delete the example code and paste the contents of projects/06-touch-coin/coin-touched.lua.
  4. Add the player-setup Script.
    • In Explorer, find ServerScriptService. Right-click it -> Insert Object -> Script.
    • Rename it PlayerSetup.
    • Paste the contents of projects/06-touch-coin/player-setup.lua.
  5. Test it.
    • Click the Play button at the top.
    • A test character appears. Walk into the coin.
    • The leaderboard at the top right should show Coins: 1.
    • The coin disappears.
    • Stop with the Stop button (or close the test window).

How the code maps to chapters

  • coin-touched.lua uses an event handler — :Connect on Touched — just like chapter 31. Finding a Player from a touching Part is two lines: a function call and an if.
  • player-setup.lua uses Instance.new (chapter 31), property assignment (folder.Name = "leaderstats"), and the PlayerAdded event. It builds a small object tree inside each player.

Underneath it is standard Lua: if, function calls, dot lookups, colon-syntax methods. The Roblox-specific bits are the names (game, Players, Instance) and the wiring (events). Everything else is like the rest of the book.

A bigger challenge (optional)

If the basic version works, try one of these:

  • Multiple coins. Right-click the Coin in Explorer, choose Duplicate, and move the copy elsewhere. Each Coin has its own Script, so it just works.
  • Respawn. Instead of destroying the Coin, hide it (coin.Transparency = 1, coin.CanTouch = false) for five seconds, then bring it back (coin.Transparency = 0, coin.CanTouch = true). Use task.wait(5) inside the touch handler.
  • A goal. When a player reaches 5 coins, show a chat message like <name> reached 5 coins! with game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = ... }).

None of these are required to finish the project.

Done?

When the Play test shows the coin disappearing and the leaderboard going up by 1, the project is complete. The very last project — Collect-All-Coins — grows this into a small game with several coins and a win condition.