SpawnLocation

Show Deprecated

SpawnLocations, or "spawns" determine where a Player respawns when they die. They can be configured to allow only certain players to use each spawn, using Teams. They also control how ForceFields are set up for newly-spawned players.

SpawnLocations can be used as checkpoints, such as in an obstacle course, using the SpawnLocation.AllowTeamChangeOnTouch property, so that when a player touches it, they will change teams to the SpawnLocation's team. In this case, only the first Team should have Team.AutoAssignable set to true, else players will not start at the first checkpoint.

Note if a SpawnLocation is added to the Workspace in Studio with SpawnLocation.Neutral set to false a Team will be created corresponding to SpawnLocation.TeamColor if it does not already exist. This behavior does not occur when spawns are created in-game using a Script or if the properties of the SpawnLocation are changed after already being added. It is recommended that developers always set up their teams manually and not rely on this behavior.

Spawning Rules

There are several rules that come into play for a given SpawnLocation when a player respawns:

See also:

  • If you'd like to configure how long it takes for a player to respawn, take a look at the RespawnTime property

Code Samples

SpawnLocation Checkpoints

1local Teams = game:GetService("Teams")
2
3-- create start team (AutoAssignable = true)
4local startTeam = Instance.new("Team")
5startTeam.Name = "Start"
6startTeam.AutoAssignable = true
7startTeam.TeamColor = BrickColor.new("White")
8startTeam.Parent = Teams
9
10-- create checkpoint teams (Autoassignable = false), ensuring all TeamColors are unique
11local team1 = Instance.new("Team")
12team1.Name = "Checkpoint 1"
13team1.AutoAssignable = false
14team1.TeamColor = BrickColor.new("Bright blue")
15team1.Parent = Teams
16
17local team2 = Instance.new("Team")
18team2.Name = "Checkpoint 2"
19team2.AutoAssignable = false
20team2.TeamColor = BrickColor.new("Bright green")
21team2.Parent = Teams
22
23local team3 = Instance.new("Team")
24team3.Name = "Checkpoint 2"
25team3.AutoAssignable = false
26team3.TeamColor = BrickColor.new("Bright red")
27team3.Parent = Teams
28
29-- create spawns
30local startSpawn = Instance.new("SpawnLocation")
31startSpawn.Anchored = true
32startSpawn.Size = Vector3.new(5, 1, 5)
33startSpawn.Neutral = false
34startSpawn.AllowTeamChangeOnTouch = false
35startSpawn.TeamColor = startTeam.TeamColor
36startSpawn.BrickColor = startTeam.TeamColor
37startSpawn.Parent = game.Workspace
38
39local team1Spawn = Instance.new("SpawnLocation")
40team1Spawn.Anchored = true
41team1Spawn.Size = Vector3.new(5, 1, 5)
42team1Spawn.Neutral = false
43team1Spawn.AllowTeamChangeOnTouch = true
44team1Spawn.TeamColor = team1.TeamColor
45team1Spawn.BrickColor = team1.TeamColor
46team1Spawn.Parent = game.Workspace
47
48local team2Spawn = Instance.new("SpawnLocation")
49team2Spawn.Anchored = true
50team2Spawn.Size = Vector3.new(5, 1, 5)
51team2Spawn.Neutral = false
52team2Spawn.AllowTeamChangeOnTouch = true
53team2Spawn.TeamColor = team2.TeamColor
54team2Spawn.BrickColor = team2.TeamColor
55team2Spawn.Parent = game.Workspace
56
57local team3Spawn = Instance.new("SpawnLocation")
58team3Spawn.Anchored = true
59team3Spawn.Size = Vector3.new(5, 1, 5)
60team3Spawn.Neutral = false
61team3Spawn.AllowTeamChangeOnTouch = true
62team3Spawn.TeamColor = team3.TeamColor
63team3Spawn.BrickColor = team3.TeamColor
64team3Spawn.Parent = game.Workspace
65
66-- position spawns
67startSpawn.CFrame = CFrame.new(0, 0.5, 0)
68team1Spawn.CFrame = CFrame.new(10, 0.5, 0)
69team2Spawn.CFrame = CFrame.new(20, 0.5, 0)
70team3Spawn.CFrame = CFrame.new(30, 0.5, 0)

Summary

Properties

Allows a Player to join the team by touching the SpawnLocation. When set to true, if a Player character comes into contact with the SpawnLocation, the player's Player.TeamColor will be set to SpawnLocation.TeamColor.

The length of time, in seconds, that a ForceField will be applied to a Player character spawning at this SpawnLocation. If Duration is zero, the ForceField is never created, and it will not trigger the Instance.DescendantAdded or Instance.ChildAdded events.

Sets whether or not the SpawnLocation is enabled. When disabled players cannot spawn at the SpawnLocation and the AllowTeamChangeOnTouch functionality is disabled.

Whether or not a SpawnLocation is affiliated with a specific team. This means that any Player, of any Team, can spawn on it if this property is set to true.

Sets what team the SpawnLocation is affiliated to. If SpawnLocation.Neutral property is false, only Players with the same Player.TeamColor as the spawn's TeamColor will be able to spawn there.

Events

Methods

Properties

AllowTeamChangeOnTouch

Allows a Player to join the team by touching the SpawnLocation. When set to true, if a Player character comes into contact with the SpawnLocation, the player's Player.TeamColor will be set to SpawnLocation.TeamColor. Player.Neutral will also be set to SpawnLocation.Neutral upon contact, meaning a player can also become neutral by touching a spawn location.

This will not function when SpawnLocation.Enabled is set to false.

Making Checkpoints

This feature is often used to make checkpoints in obstacle courses or similar games.

Duration

The length of time, in seconds, that a ForceField will be applied to a Player character spawning at this SpawnLocation. If Duration is zero, the ForceField is never created, and it will not trigger the Instance.DescendantAdded or Instance.ChildAdded events.

This default value of this property is 10 seconds.

The duration feature allows developers to easily give Players protection from 'spawn killing' which can be a frustrating experience for players. Note, ForceFields will only protect users from Explosions and Weapons that use Humanoid:TakeDamage() to deal damage or otherwise check for a ForceField.

Enabled

Sets whether or not the SpawnLocation is enabled. When disabled players cannot spawn at the SpawnLocation and the SpawnLocation.AllowTeamChangeOnTouch functionality is disabled.

This property provides the most convenient way of preventing Players from spawning at a spawn.

Note, although team changing on touch using SpawnLocation.AllowTeamChangeOnTouch is disabled when Enabled is set to false, other touched events using BasePart.Touched will still fire.

Neutral

Whether or not a spawn is affiliated with a specific team. This means that any Player, of any Team, can spawn on it if this property is set to true.

If Neutral is set to false, only players whose Player.TeamColor is equal to SpawnLocation.TeamColor can use the SpawnLocation.

If SpawnLocation.AllowTeamChangeOnTouch is true Player.Neutral will be set to this property upon contact with the spawn.

TeamColor

The TeamColor property sets what team the SpawnLocation is affiliated to. If SpawnLocation.Neutral property is false, only Players with the same Player.TeamColor as the spawn's TeamColor will be able to spawn there.

If SpawnLocation.AllowTeamChangeOnTouch is true Player.Neutral will be set to this property upon contact with the spawn.

Events

Methods