Part 7 mini-project: Collect-All-Coins
The book's last project builds on the Touch-to-Collect Coin. You scatter several coins, count how many a player picks up, and announce a win on the last one. It uses all of Part 7 — Instances, events, services, leaderstats — plus a Part 6 loop over many objects.
What to build
When the experience runs:
- Each player gets a
leaderstatsfolder withCoinsat0(as before). - Several coins sit in the world inside one Folder.
- Walking into a coin adds
1to that player'sCoinsand removes it. - When the last coin is collected, the game prints a win message.
Files
Two scripts are in projects/collect-all-coins/:
player-setup.lua— aScriptin ServerScriptService. BuildsleaderstatsandCoinsfor each joining player.coins-manager.lua— aScriptin ServerScriptService. Finds every coin, wires up eachTouchedevent, counts pickups, fires the win.
Studio setup, step by step
- Open Studio with the Baseplate template.
- Make a Coins folder.
- In the Explorer, right-click
Workspace → Insert Object →
Folder. Rename it
Coins(F2).
- In the Explorer, right-click
Workspace → Insert Object →
Folder. Rename it
- Add some coins.
- Right-click the Coins folder → Insert Object → Part.
- For that Part set, in Properties:
Anchored=true,Shape=Cylinder(optional),Size=2, 0.4, 2,BrickColor=Bright yellow, and aPositionthe player can reach. - Duplicate it (right-click →
Duplicate) a few times and spread the copies around.
Each copy stays inside the
Coinsfolder.
- Add the two scripts.
- Right-click ServerScriptService → Insert
Object → Script. Rename it
PlayerSetupand pasteplayer-setup.lua. - Add a second Script named
CoinsManagerand pastecoins-manager.lua.
- Right-click ServerScriptService → Insert
Object → Script. Rename it
- Test it. Press Play, walk over every coin, and watch the leaderboard climb. When the last coin vanishes, the Output panel prints the win message.
How the code works
coins-manager.luacounts the coins with#coinsFolder:GetChildren()— the list length from Chapter 22.- It loops over them (Chapter 28) and connects each
Touchedevent (Chapter 33). - Each handler finds the player (Chapter 33), bumps their
Coins(Chapter 35), removes the coin, and adds one to a sharedcollectedcounter (Chapter 20). - When
collectedreachestotal, the win message prints.
The if coin.Parent == nil then return end line is a
debounce: a destroyed coin's Parent is nil, so
leftover touches are skipped.
A bigger challenge (optional)
- Per-player wins. Give each player their own count so two can race; announce the first to a set number.
- Respawn the coins. After the win,
task.wait, thenClonethe coins back for a new round.
Done?
When the coins can be collected, the leaderboard counts them, and the win fires on the last one — the project, and the book, are done.
You started with words on paper and ended with a playable Roblox scene. Every Roblox tutorial from here reads like the next chapter: same language, same patterns, just more services, events, Instances. Go make something.