Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 37 ยท Projects and Practice

Project: Build an Obby With Checkpoints and a Timer

Build a complete obstacle course in Roblox Studio and Luau with kill bricks, checkpoints, a stage counter, a finish line and a speedrun timer, plus runnable logic models.

An obby (obstacle course) is the classic first experience: run, jump, avoid hazards, reach the end. It is small enough to finish in an afternoon and uses nearly everything you have learned: parts, scripts, events, leaderstats, tweens and saving. In this project you build the logic in four steps and test each piece.

The Roblox code is shown read-only, because Studio cannot run here. Each step also has a JavaScript stand-in that models the same logic, so you can check the rules before you build them in Studio.

Plan

Your obby will have:

  1. A course of parts from a start platform to a finish pad.
  2. Kill bricks that send the player back.
  3. Checkpoints that remember the furthest stage reached.
  4. A stage counter in leaderstats.
  5. A timer that records the run time and a best time.

Set up the workspace first. Make a folder Workspace > Checkpoints and put numbered Parts inside it, named 1, 2, 3, and so on, in course order. Place a SpawnLocation at the start. Make the course parts Anchored. Add a folder Workspace > KillBricks for hazards, such as red neon parts.

Obby building blocks

Kill bricks Touch one and you reset.
Checkpoints Numbered parts that save progress.
Stage counter leaderstats show the stage.
Timer Seconds from start to finish.

Folders with numbered parts let one script handle everything.

1 / 2

Step 1: kill bricks

One script handles every brick in the folder, using the tagging idea from Services.

LUA
-- Script in ServerScriptService
local Players = game:GetService("Players")
local killBricks = workspace:WaitForChild("KillBricks")

local function connectBrick(brick)
	brick.Touched:Connect(function(hit)
		local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
		if humanoid then
			humanoid.Health = 0
		end
	end)
end

for _, brick in killBricks:GetChildren() do
	connectBrick(brick)
end

hit is whichever body part touched the brick; its parent is the character model, which holds the Humanoid. Setting Health to zero kills the character, and the player respawns.

Step 2: checkpoints and stages

Each player gets a Stage value that equals the highest checkpoint number they touched. When they respawn, they appear at that checkpoint instead of the start.

LUA
local checkpoints = workspace:WaitForChild("Checkpoints")

local function setupPlayer(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Value = 0
	stage.Parent = leaderstats

	player.CharacterAdded:Connect(function(character)
		local number = stage.Value
		local checkpoint = checkpoints:FindFirstChild(tostring(number))
		if checkpoint then
			-- wait one frame, then move the new character on top of the checkpoint
			task.wait()
			character:PivotTo(checkpoint.CFrame + Vector3.new(0, 4, 0))
		end
	end)
end

Players.PlayerAdded:Connect(setupPlayer)

for _, checkpoint in checkpoints:GetChildren() do
	checkpoint.Touched:Connect(function(hit)
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		if not player then return end
		local stage = player.leaderstats.Stage
		local number = tonumber(checkpoint.Name)
		if number and number > stage.Value then -- only forward progress
			stage.Value = number
		end
	end)
end

Two details prevent bugs. The number > stage.Value check stops a player from going back to an earlier checkpoint. And Players:GetPlayerFromCharacter(hit.Parent) returns nil for a non-player thing touching the part, such as a falling box, so those are ignored.

Before building this in Studio, test the rules in the model below.

JS Checkpoint and kill brick logic (JavaScript stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The player dies at stage 2 and returns there, ignores an old checkpoint, and moves forward again. Those three behaviors are your acceptance tests in Studio too.

Step 3: the finish line and timer

Start a timer when the player first moves (or when their character loads), and stop it when they touch the finish pad.

LUA
local finish = workspace:WaitForChild("Finish")
local startTimes = {}
local bestTimes = {} -- later: save in a DataStore, see "Saving Player Data"

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		if not startTimes[player] then
			startTimes[player] = os.clock()
		end
	end)
end)

finish.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if not player or not startTimes[player] then return end

	local elapsed = os.clock() - startTimes[player]
	startTimes[player] = nil

	local best = bestTimes[player]
	if not best or elapsed < best then
		bestTimes[player] = elapsed
	end
	print(("%s finished in %.2f s (best %.2f s)"):format(player.Name, elapsed, bestTimes[player]))

	player.leaderstats.Stage.Value = 0 -- reset for another run
end)

The startTimes[player] = nil line is the debounce: without it, a single touch could be counted again and again. Remember to clear tables on PlayerRemoving.

JS Timer and best time (JavaScript stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Step 4: polish

  • Visual feedback: show the stage and timer in a GUI (see GUI basics); color checkpoints green when reached with a tween.
  • Moving hazards: tween anchored parts back and forth for spinning bars or sliding platforms.
  • Difficulty curve: make early stages easy, add a rest checkpoint every few stages, and end on a mix of everything you taught.
  • Sound and particles: play a chime on a checkpoint, on the client.
  • Saving: store Stage and best time with the pattern from Saving Player Data.
  • Safety: all of this logic runs on the server, so exploiters cannot set their stage. A client that teleports does not help, since stages count only when the server sees the touch. Add a sanity check on speed from anti-exploit security to catch skipped stages.

Test plan

  1. Run through the whole course once without dying.
  2. Die at each stage and confirm you respawn at the right place.
  3. Touch an old checkpoint and confirm the stage does not drop.
  4. Finish and confirm the time prints; do it twice and check the best time.
  5. Test with two local players to be sure each has independent stages.
  6. Check the Output window for errors.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does the checkpoint script compare number > stage.Value?

    The comparison keeps progress moving forward only.
  2. 2. How does the script know which player touched a part?

    hit is a body part; its parent is the character model, which GetPlayerFromCharacter maps to the Player (or nil).
  3. 3. Why set startTimes[player] = nil when the player finishes?

    Touched can fire repeatedly, so clearing the start time acts as a debounce.
  4. 4. Why does the obby logic live in server scripts?

    Server authority keeps progress trustworthy.

Summary

  • An obby needs a course, kill bricks, checkpoints, a stage counter and a finish with a timer.
  • One server script can handle a whole folder of bricks or checkpoints with a loop.
  • Use Players:GetPlayerFromCharacter(hit.Parent) to turn a touch into a player, and ignore non-players.
  • Keep progress forward-only, debounce the finish, and clean up tables on leave.
  • Add GUI, tweens, saving and sanity checks to turn the prototype into a polished game.

Next: Project: Coin Collector With a Shop