Skip to content

Tutorial: an obby ​

An obby is an obstacle course: jump from platform to platform, avoid the lava, reach the finish. In this tutorial you build one with KHIM's gameplay objects - which work with no code - then add one short script for the finish line.

It takes about 20 minutes. You need KHIM Engine installed (Install and your first world).

1. Start the world ​

On Home, press New world, name it My Obby, pick Flat ground and press Create. You get a floor called Ground and a SpawnLocation, where players appear.

TIP

The Obby template is a finished version of a course like this one. Open it afterwards to compare.

2. Build the platforms ​

  1. Insert a Part (the + on the tool dock, or right-click the view).
  2. In the Inspector set its Size to 6, 1, 6. Leave Anchored ticked - an anchored part never falls or gets pushed.
  3. Move it (Ctrl 2) a jump away from the spawn: about 10 units ahead and 1 up.
  4. Press Ctrl D to duplicate it, and move the copy one jump further. Press Ctrl D again: each new copy lands as far again from the last, so a staircase of platforms is one drag and a few Ctrl D.
  5. Give the platforms colours. Rename them in the Hierarchy (F2): Stage1, Stage2...

Press F5 now and then to check every jump can be made. A character walks at 20 units a second and jumps about 6 units high.

3. Add lava ​

  1. Insert a thin part across one platform - size 3, 0.2, 2 - and make it red with the Neon material. Name it Lava.
  2. With it selected, open Insert Object (right-click its row in the Hierarchy) and pick Hazard from Gameplay (no script needed).

That's it: a Hazard hurts whoever touches its part. Its Damage is 100 by default, a whole health bar, so lava kills at once. A lower number hurts each second the player stays on it.

4. Add checkpoints ​

Put a Checkpoint on every few platforms (select the platform, Insert Object > Checkpoint). After a player touches one, they come back there when they die instead of at the spawn.

5. Add coins ​

  1. Insert a Sphere, size 1.5, 1.5, 1.5, yellow, over a platform. Name it Coin.
  2. Insert Object > Pickup on it.

A Pickup makes its part a collectible: anchored and walk-through, it adds 1 to the player's Coins stat (a column in the player list, made the first time) and comes back after 10 seconds. Change Stat, Amount and Comes back after in the Inspector. Duplicate the coin along the course.

6. A jump pad ​

Insert a flat part where a jump is too far, and put a Boost on it. Touching it gives the player more walk speed and jump power for a few seconds (Walk speed, Jump power and Lasts in the Inspector).

7. The finish line ​

The last gameplay piece needs a few lines of code. Make a big gold platform at the end named Finish, then right-click it in the Hierarchy > Insert Object > Script. Double-click the script to open it and replace its text with:

lua
-- The finish: a win in the player list, a line in the chat, then back to the start.
local finish = script.parent
local arriving = {}

players.joined:connect(function(player)
    player.stats.Wins = 0 -- a "Wins" column in the player list
end)

finish.touched:connect(function(hit)
    local player = players.fromPart(hit)
    if not player or arriving[player.name] then return end
    arriving[player.name] = true

    player.stats.Wins += 1
    chat.send(player.displayName .. " reached the top!")

    task.wait(1.5)
    player.position = world.SpawnLocation.position + vec3(0, 4, 0)
    arriving[player.name] = nil
end)

What it does:

  • script.parent is the part the script is in - the Finish.
  • players.joined runs once for every player who joins. player.stats.Wins = 0 adds a Wins column to the player list (Tab).
  • finish.touched fires whenever something touches the part. players.fromPart(hit) turns the touching part into a player, or nil when it wasn't one.
  • arriving stops the same player winning several times while they stand on the platform.
  • Setting player.position from a server Script teleports them.

Read Scripting basics to understand every line.

8. Test it properly ​

Press F5 and play the whole course. Check:

  • every jump is possible, with and without the jump pad;
  • the lava kills and you come back at the last checkpoint;
  • the coins count up in the player list and come back;
  • the finish adds a win and sends you back.

The Console (Ctrl J) shows script errors in red - click one to jump to the line. See Testing and debugging.

9. Go live ​

Save (Ctrl S), then press Go live (Alt P). Pick Create a new game, give it a name and press Create. Your obby is on KHIM, private to start with. Go live and the Workshop explains how to make it public and update it.

Ideas to go further ​