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
Player/Neutral will also be set to
SpawnLocation/Neutral upon contact, meaning a player can also become neutral by touching a spawn location.
SpawnLocation/Enabledis set to false.
This feature is often used to make checkpoints in obstacle courses or similar games. See
Articles/How to use Spawn Objects with Roblox Studio|Using Player Spawns for details.
This sample demonstrates how SpawnLocations can be used to make a checkpoint system. Typically this would be done Studio and not in Lua, but this example serves as a comprehensive example of what Team and SpawnLocation properties need to be used to achieve this setup.
local Teams = game:GetService("Teams") -- create start team (AutoAssignable = true) local startTeam = Instance.new("Team", Teams) startTeam.Name = "Start" startTeam.AutoAssignable = true startTeam.TeamColor = BrickColor.new("White") -- create checkpoint teams (Autoassignable = false), ensuring all TeamColors are unique local team1 = Instance.new("Team", Teams) team1.Name = "Checkpoint 1" team1.AutoAssignable = false team1.TeamColor = BrickColor.new("Bright blue") local team2 = Instance.new("Team", Teams) team2.Name = "Checkpoint 2" team2.AutoAssignable = false team2.TeamColor = BrickColor.new("Bright green") local team3 = Instance.new("Team", Teams) team3.Name = "Checkpoint 2" team3.AutoAssignable = false team3.TeamColor = BrickColor.new("Bright red") -- create spawns local startSpawn = Instance.new("SpawnLocation", game.Workspace) startSpawn.Anchored = true startSpawn.Size = Vector3.new(5, 1, 5) startSpawn.Neutral = false startSpawn.AllowTeamChangeOnTouch = false startSpawn.TeamColor = startTeam.TeamColor startSpawn.BrickColor = startTeam.TeamColor local team1Spawn = Instance.new("SpawnLocation", game.Workspace) team1Spawn.Anchored = true team1Spawn.Size = Vector3.new(5, 1, 5) team1Spawn.Neutral = false team1Spawn.AllowTeamChangeOnTouch = true team1Spawn.TeamColor = team1.TeamColor team1Spawn.BrickColor = team1.TeamColor local team2Spawn = Instance.new("SpawnLocation", game.Workspace) team2Spawn.Anchored = true team2Spawn.Size = Vector3.new(5, 1, 5) team2Spawn.Neutral = false team2Spawn.AllowTeamChangeOnTouch = true team2Spawn.TeamColor = team2.TeamColor team2Spawn.BrickColor = team2.TeamColor local team3Spawn = Instance.new("SpawnLocation", game.Workspace) team3Spawn.Anchored = true team3Spawn.Size = Vector3.new(5, 1, 5) team3Spawn.Neutral = false team3Spawn.AllowTeamChangeOnTouch = true team3Spawn.TeamColor = team3.TeamColor team3Spawn.BrickColor = team3.TeamColor -- position spawns startSpawn.CFrame = CFrame.new(0, 0.5, 0) team1Spawn.CFrame = CFrame.new(10, 0.5, 0) team2Spawn.CFrame = CFrame.new(20, 0.5, 0) team3Spawn.CFrame = CFrame.new(30, 0.5, 0)