Roblox Studio · Lesson 11

Checkpoint: start again after failure

Use SpawnLocation and RespawnLocation to save the checkpoint of this game and test the difference between rebirth and re-entry.

10–15 years old 60 minutes SpawnLocation Hands-on practice Testing and Saving

Course overview

When they reach the checkpoint, failure does not have to be repeated from the farthest distance.

A challenging route can also be player-friendly. Checkpoints remember where you have been in the game, making failure a short retry.

This course does not produce a "regeneration effect" by mobile cameras, but rather uses Roblox's SpawnLocation and player's RespawnLocation.

01 · BEFORE

Before starting

Be able to build a platform and understand Player and Character. Use standalone Lesson11 Baseplate.

02 · MAKE

Your work

A starting point and an activatable checkpoint, both for correct birth.

03 · CHECK

Complete flag

Spawn at the starting point first, then respawn at the checkpoint after activation; the other player will not be changed together.

Official screenshots of placing two SpawnLocations in the scene
Figure 11-1: Official scene reference: Two SpawnLocations can represent the starting point and checkpoint. First follow the steps in this lesson to distinguish the Enabled status to avoid random births.Roblox Creator Documentation · CC BY 4.0 · The original image has not been modified · Description of the permit

Learning route

Prepare first, then do it; after seeing the result, remember to save it.

Every time a small step is completed, it is tested. Say what you expect to see first, and then use Play and Output to check it. Don't rush to write all the code at once.

1

01 · SpawnLocation must be used

Ordinary Part can be used as a visual mark, but cannot be directly assigned to RespawnLocation. You need two real SpawnLocation objects.

2

02 · Mark the checkpoint on the player

player.RespawnLocation saves a spawn point object reference. It belongs to this player and not to the Workspace shared by all players.

3

03 · Distinguish between personal progress and shared appearance

If you turn the checkpoint green on the server, everyone will see the green color. This does not mean that everyone has it activated. When determining personal progress, look at the corresponding Player.RespawnLocation.

4

04 · Take a short road between two spawn points

Now add three more wide platforms and place the checkpoint after completing the first challenge. Make sure the solo respawn feature is reliable before making the level difficult.

5

05 · Try "two people with different progress"

Multi-person inspection can best detect the error of "writing one person's progress as a global variable". A activates the checkpoint and B is still at the starting point. The two should respawn at different locations.

Step by step

01 · SpawnLocation must be used

Ordinary Part can be used as a visual mark, but cannot be directly assigned to RespawnLocation. You need two real SpawnLocation objects.

In order to avoid randomly selecting checkpoints at the first birth, set the starting point Enabled=true and checkpoint Enabled=false. Enable checkpoints when players activate, and give each new player an explicit StartSpawn.

  1. Rename the existing SpawnLocation to StartSpawn and set the Position to 0, 0.5, 0.
  2. Insert the second SpawnLocation, name it Checkpoint, and set the Position to 0, 0.5, -30.
  3. Both Anchored=true, Neutral=true, AllowTeamChangeOnTouch=false; Checkpoint.CanTouch=true, Enabled=false.
  4. Create CheckpointManager in ServerScriptService.

Step by step

02 · Mark the checkpoint on the player

player.RespawnLocation saves a spawn point object reference. It belongs to this player and not to the Workspace shared by all players.

Scripts also specify a starting point for new players. So even if someone else has turned on Checkpoint, the player that entered will start with StartSpaawn.

  1. Paste the complete script.
  2. Don't go to the checkpoint after playing, reset the character once, and confirm that it is still at the starting point.
  3. Go to the Checkpoint again and see if the Output displays the activation message.
ServerScriptService > CheckpointManager · Complete scriptLuau
local Players = game:GetService("Players")
local startSpawn = workspace:WaitForChild("StartSpawn")
local checkpoint = workspace:WaitForChild("Checkpoint")

local function setupPlayer(player)
    player.RespawnLocation = startSpawn
end
Players.PlayerAdded:Connect(setupPlayer)
for _, player in ipairs(Players:GetPlayers()) do setupPlayer(player) end

checkpoint.Touched:Connect(function(hit)
    local character = hit:FindFirstAncestorOfClass("Model")
    local player = character and Players:GetPlayerFromCharacter(character)
    local humanoid = character and character:FindFirstChildOfClass("Humanoid")
    if not player or not humanoid or humanoid.Health <= 0 then return end
    if player.RespawnLocation == checkpoint then return end
    checkpoint.Enabled = true
    player.RespawnLocation = checkpoint
    print(player.Name, "Checkpoint activated")
end)
Can not delete folder: %s: Invalid operation
Figure 11-2: Official spawn point selection screenshot: Confirm that the SpawnLocation object is selected, and then modify its properties; do not just change the name of the ordinary Part.Roblox Creator Documentation · CC BY 4.0 · The original image has not been modified · Description of the permit

Step by step

03 · Distinguish between personal progress and shared appearance

If you turn the checkpoint green on the server, everyone will see the green color. This does not mean that everyone has it activated. When determining personal progress, look at the corresponding Player.RespawnLocation.

Therefore, this lesson does not regard the entire scene turning green as evidence of "I have saved". Read Output and Player Properties first; once you learn LocalScript, you can create prompts that are only visible to you.

  1. View your own RespawnLocation from the server's perspective while running.
  2. Before activation it points to StartSpawn and after activation it points to Checkpoint.
  3. The checkpoint is not an immediate transfer button. After assignment, it will only be used in the next rebirth.

Step by step

04 · Take a short road between two spawn points

Now add three more wide platforms and place the checkpoint after completing the first challenge. Make sure the solo respawn feature is reliable before making the level difficult.

There should be space above the spawn point, not against a low roof or caught in a wall. The character needs to stand safely when it appears, and cannot fall down immediately after being born.

  1. Adds three mechanisms between the starting point and the check point.
  2. Test that you can at least stand and turn around safely around checkpoints.
  3. Baseplate is retained in this lesson and tested by resetting the character without creating a dangerous gap first.

Step by step

05 · Try "two people with different progress"

Multi-person inspection can best detect the error of "writing one person's progress as a global variable". A activates the checkpoint and B is still at the starting point. The two should respawn at different locations.

This is just a record of this session. Stop re-enters after it, and the new Player continues to start with StarSpawon; this is similar to the life cycle of the 10th class gold coin.

  1. A resets after activation and should appear in Checkpoint.
  2. B Direct reset without activation, should appear in StartSpawn.
  3. Stop the test and start again, confirm that the starting point rule is restored.

Homework

It's your turn to change and make your own version.

1 Friendly foothold

Add a wide platform and obvious road signs to the checkpoint to ensure that it is not blocked after birth.

2 Test record

Record the birth position before activation, after activation, and re-Play respectively.

3 Select: Second Checkpoint

Copy a new SpawnLocation and add independent touch processing to it; first draw the order of the two checkpoints.

Completion criteria:First verify the work in Playtest, then click Stop and save it as "Initials_Lesson11" or the corresponding Homework copy; do not overwrite the runnable version of the previous lesson.

Exit questions

Answer it yourself first, and then expand on it.

Can an ordinary Part be used directly as RespawnLocation?

No, SpawnLocation is required.

Will you move the player right away after the value is given?

No, it determines the location of the next rebirth.

Why do we also set a starting point for players who join later?

To avoid other places of birth where new players can be born randomly to midway.

Did everyone save the checkpoint when they saw it green?

Not necessarily, the shared color and each player's RespawnLocation are two states.

Explore further

This is where we start when we need to check the data.

The text code can be copied directly. First confirm the script type, placement, and whether this code is a complete version or a small experiment; do not run multiple versions of the same script superimposed. The source of the interface reference picture has been marked. The object names in the picture may be different from those in this lesson. Please refer to the operation steps.

Download the code and placement instructions for this lesson