SpawnLocation

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้จะพร้อมใช้งานในภาษาที่คุณเลือกในเร็วๆ นี้

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

ตัวอย่างโค้ด

SpawnLocation Checkpoints

local Teams = game:GetService("Teams")
-- create start team (AutoAssignable = true)
local startTeam = Instance.new("Team")
startTeam.Name = "Start"
startTeam.AutoAssignable = true
startTeam.TeamColor = BrickColor.new("White")
startTeam.Parent = Teams
-- create checkpoint teams (Autoassignable = false), ensuring all TeamColors are unique
local team1 = Instance.new("Team")
team1.Name = "Checkpoint 1"
team1.AutoAssignable = false
team1.TeamColor = BrickColor.new("Bright blue")
team1.Parent = Teams
local team2 = Instance.new("Team")
team2.Name = "Checkpoint 2"
team2.AutoAssignable = false
team2.TeamColor = BrickColor.new("Bright green")
team2.Parent = Teams
local team3 = Instance.new("Team")
team3.Name = "Checkpoint 2"
team3.AutoAssignable = false
team3.TeamColor = BrickColor.new("Bright red")
team3.Parent = Teams
-- create spawns
local startSpawn = Instance.new("SpawnLocation")
startSpawn.Anchored = true
startSpawn.Size = Vector3.new(5, 1, 5)
startSpawn.Neutral = false
startSpawn.AllowTeamChangeOnTouch = false
startSpawn.TeamColor = startTeam.TeamColor
startSpawn.BrickColor = startTeam.TeamColor
startSpawn.Parent = game.Workspace
local team1Spawn = Instance.new("SpawnLocation")
team1Spawn.Anchored = true
team1Spawn.Size = Vector3.new(5, 1, 5)
team1Spawn.Neutral = false
team1Spawn.AllowTeamChangeOnTouch = true
team1Spawn.TeamColor = team1.TeamColor
team1Spawn.BrickColor = team1.TeamColor
team1Spawn.Parent = game.Workspace
local team2Spawn = Instance.new("SpawnLocation")
team2Spawn.Anchored = true
team2Spawn.Size = Vector3.new(5, 1, 5)
team2Spawn.Neutral = false
team2Spawn.AllowTeamChangeOnTouch = true
team2Spawn.TeamColor = team2.TeamColor
team2Spawn.BrickColor = team2.TeamColor
team2Spawn.Parent = game.Workspace
local team3Spawn = Instance.new("SpawnLocation")
team3Spawn.Anchored = true
team3Spawn.Size = Vector3.new(5, 1, 5)
team3Spawn.Neutral = false
team3Spawn.AllowTeamChangeOnTouch = true
team3Spawn.TeamColor = team3.TeamColor
team3Spawn.BrickColor = team3.TeamColor
team3Spawn.Parent = game.Workspace
-- 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)

สรุป

คุณสมบัติ

คุณสมบัติรับทอดมาจากPart
  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Sets the overall shape of the object.

คุณสมบัติรับทอดมาจากBasePart
  • อ่านพร้อมๆ กัน

    Determines whether a part is immovable by physics.

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    The angular velocity of the part's assembly.

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    The center of mass of the part's assembly in world space.

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    The linear velocity of the part's assembly.

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    The total mass of the part's assembly.

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    A reference to the root part of the assembly.

  • อ่านพร้อมๆ กัน
  • อ่านพร้อมๆ กัน

    Determines the type of surface for the Back face of a part (+Z direction).

  • อ่านพร้อมๆ กัน

    Determines the type of surface for the Bottom face of a part (-Y direction).

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Determines the color of a part.

  • อ่านพร้อมๆ กัน

    Determines the position and orientation of the BasePart in the world.

  • อ่านพร้อมๆ กัน

    Determines whether a part may collide with other parts.

  • อ่านพร้อมๆ กัน

    Determines whether the part is considered during spatial query operations.

  • อ่านพร้อมๆ กัน

    Determines if Touched and TouchEnded events fire on the part.

  • อ่านพร้อมๆ กัน

    Determines whether or not a part casts a shadow.

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Describes the world position in which a part's center of mass is located.

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Describes the name of a part's collision group.

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Determines the color of a part.

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Indicates the current physical properties of the part.

  • อ่านพร้อมๆ กัน

    Determines several physical properties of a part.

  • อ่านพร้อมๆ กัน

    Used to enable or disable aerodynamic forces on parts and assemblies.

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    The CFrame of the physical extents of the BasePart.

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    The actual physical size of the BasePart as regarded by the physics engine.

  • อ่านพร้อมๆ กัน

    Determines the type of surface for the Front face of a part (-Z direction).

  • อ่านพร้อมๆ กัน

    Determines the type of surface for the Left face of a part (-X direction).

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Determines a multiplier for BasePart.Transparency that is only visible to the local client.

  • อ่านพร้อมๆ กัน

    Determines whether a part is selectable in Studio.

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Describes the mass of the part, the product of its density and volume.

  • อ่านพร้อมๆ กัน

    Determines whether the part contributes to the total mass or inertia of its rigid body.

  • อ่านพร้อมๆ กัน

    Determines the texture and default physical properties of a part.

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    The name of MaterialVariant.

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Describes the rotation of the part in the world.

  • อ่านพร้อมๆ กัน

    Specifies the offset of the part's pivot from its CFrame.

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Describes the position of the part in the world.

  • ซ่อนอยู่
    อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Time since last recorded physics update.

  • อ่านพร้อมๆ กัน

    Determines how much a part reflects the skybox.

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Describes the smallest change in size allowable by the Resize method.

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Describes the faces on which a part may be resized.

  • อ่านพร้อมๆ กัน

    Determines the type of surface for the Right face of a part (+X direction).

  • อ่านพร้อมๆ กัน

    The main rule in determining the root part of an assembly.

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    The rotation of the part in degrees for the three axes.

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Determines the dimensions of a part (length, width, height).

  • อ่านพร้อมๆ กัน

    Determines the type of surface for the Top face of a part (+Y direction).

  • อ่านพร้อมๆ กัน

    Determines how much a part can be seen through (the inverse of part opacity).

คุณสมบัติรับทอดมาจากPVInstance
  • ไม่ซ้ำ
    ไม่สามารถเขียนสคริปต์
    อ่านพร้อมๆ กัน
  • ไม่ซ้ำ
    ไม่สามารถเขียนสคริปต์
    อ่านพร้อมๆ กัน

วิธีการ

วิธีการรับทอดมาจากBasePartวิธีการรับทอดมาจากPVInstance

อีเวนต์

อีเวนต์รับทอดมาจากBasePart

คุณสมบัติ

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.

ตัวอย่างโค้ด

SpawnLocation Checkpoints

local Teams = game:GetService("Teams")
-- create start team (AutoAssignable = true)
local startTeam = Instance.new("Team")
startTeam.Name = "Start"
startTeam.AutoAssignable = true
startTeam.TeamColor = BrickColor.new("White")
startTeam.Parent = Teams
-- create checkpoint teams (Autoassignable = false), ensuring all TeamColors are unique
local team1 = Instance.new("Team")
team1.Name = "Checkpoint 1"
team1.AutoAssignable = false
team1.TeamColor = BrickColor.new("Bright blue")
team1.Parent = Teams
local team2 = Instance.new("Team")
team2.Name = "Checkpoint 2"
team2.AutoAssignable = false
team2.TeamColor = BrickColor.new("Bright green")
team2.Parent = Teams
local team3 = Instance.new("Team")
team3.Name = "Checkpoint 2"
team3.AutoAssignable = false
team3.TeamColor = BrickColor.new("Bright red")
team3.Parent = Teams
-- create spawns
local startSpawn = Instance.new("SpawnLocation")
startSpawn.Anchored = true
startSpawn.Size = Vector3.new(5, 1, 5)
startSpawn.Neutral = false
startSpawn.AllowTeamChangeOnTouch = false
startSpawn.TeamColor = startTeam.TeamColor
startSpawn.BrickColor = startTeam.TeamColor
startSpawn.Parent = game.Workspace
local team1Spawn = Instance.new("SpawnLocation")
team1Spawn.Anchored = true
team1Spawn.Size = Vector3.new(5, 1, 5)
team1Spawn.Neutral = false
team1Spawn.AllowTeamChangeOnTouch = true
team1Spawn.TeamColor = team1.TeamColor
team1Spawn.BrickColor = team1.TeamColor
team1Spawn.Parent = game.Workspace
local team2Spawn = Instance.new("SpawnLocation")
team2Spawn.Anchored = true
team2Spawn.Size = Vector3.new(5, 1, 5)
team2Spawn.Neutral = false
team2Spawn.AllowTeamChangeOnTouch = true
team2Spawn.TeamColor = team2.TeamColor
team2Spawn.BrickColor = team2.TeamColor
team2Spawn.Parent = game.Workspace
local team3Spawn = Instance.new("SpawnLocation")
team3Spawn.Anchored = true
team3Spawn.Size = Vector3.new(5, 1, 5)
team3Spawn.Neutral = false
team3Spawn.AllowTeamChangeOnTouch = true
team3Spawn.TeamColor = team3.TeamColor
team3Spawn.BrickColor = team3.TeamColor
team3Spawn.Parent = game.Workspace
-- 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)

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.

ตัวอย่างโค้ด

SpawnLocation ForceField

local spawnLocation = Instance.new("SpawnLocation")
spawnLocation.Anchored = true
spawnLocation.Size = Vector3.new(5, 1, 5)
spawnLocation.Neutral = true -- anyone can spawn here
spawnLocation.Duration = 20
spawnLocation.Parent = workspace

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.

ตัวอย่างโค้ด

SpawnLocation Enabled

local spawnLocation = Instance.new("SpawnLocation")
spawnLocation.Anchored = true
spawnLocation.Size = Vector3.new(5, 1, 5)
spawnLocation.Neutral = true -- anyone can spawn here
spawnLocation.Enabled = true
spawnLocation.Parent = workspace
local function onEnabledChanged()
spawnLocation.Transparency = spawnLocation.Enabled and 0 or 0.5
end
spawnLocation:GetPropertyChangedSignal("Enabled"):Connect(onEnabledChanged)
task.wait(5)
spawnLocation.Enabled = false -- transparency = 0.5

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.

ตัวอย่างโค้ด

SpawnLocation Checkpoints

local Teams = game:GetService("Teams")
-- create start team (AutoAssignable = true)
local startTeam = Instance.new("Team")
startTeam.Name = "Start"
startTeam.AutoAssignable = true
startTeam.TeamColor = BrickColor.new("White")
startTeam.Parent = Teams
-- create checkpoint teams (Autoassignable = false), ensuring all TeamColors are unique
local team1 = Instance.new("Team")
team1.Name = "Checkpoint 1"
team1.AutoAssignable = false
team1.TeamColor = BrickColor.new("Bright blue")
team1.Parent = Teams
local team2 = Instance.new("Team")
team2.Name = "Checkpoint 2"
team2.AutoAssignable = false
team2.TeamColor = BrickColor.new("Bright green")
team2.Parent = Teams
local team3 = Instance.new("Team")
team3.Name = "Checkpoint 2"
team3.AutoAssignable = false
team3.TeamColor = BrickColor.new("Bright red")
team3.Parent = Teams
-- create spawns
local startSpawn = Instance.new("SpawnLocation")
startSpawn.Anchored = true
startSpawn.Size = Vector3.new(5, 1, 5)
startSpawn.Neutral = false
startSpawn.AllowTeamChangeOnTouch = false
startSpawn.TeamColor = startTeam.TeamColor
startSpawn.BrickColor = startTeam.TeamColor
startSpawn.Parent = game.Workspace
local team1Spawn = Instance.new("SpawnLocation")
team1Spawn.Anchored = true
team1Spawn.Size = Vector3.new(5, 1, 5)
team1Spawn.Neutral = false
team1Spawn.AllowTeamChangeOnTouch = true
team1Spawn.TeamColor = team1.TeamColor
team1Spawn.BrickColor = team1.TeamColor
team1Spawn.Parent = game.Workspace
local team2Spawn = Instance.new("SpawnLocation")
team2Spawn.Anchored = true
team2Spawn.Size = Vector3.new(5, 1, 5)
team2Spawn.Neutral = false
team2Spawn.AllowTeamChangeOnTouch = true
team2Spawn.TeamColor = team2.TeamColor
team2Spawn.BrickColor = team2.TeamColor
team2Spawn.Parent = game.Workspace
local team3Spawn = Instance.new("SpawnLocation")
team3Spawn.Anchored = true
team3Spawn.Size = Vector3.new(5, 1, 5)
team3Spawn.Neutral = false
team3Spawn.AllowTeamChangeOnTouch = true
team3Spawn.TeamColor = team3.TeamColor
team3Spawn.BrickColor = team3.TeamColor
team3Spawn.Parent = game.Workspace
-- 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)

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.

ตัวอย่างโค้ด

SpawnLocation Checkpoints

local Teams = game:GetService("Teams")
-- create start team (AutoAssignable = true)
local startTeam = Instance.new("Team")
startTeam.Name = "Start"
startTeam.AutoAssignable = true
startTeam.TeamColor = BrickColor.new("White")
startTeam.Parent = Teams
-- create checkpoint teams (Autoassignable = false), ensuring all TeamColors are unique
local team1 = Instance.new("Team")
team1.Name = "Checkpoint 1"
team1.AutoAssignable = false
team1.TeamColor = BrickColor.new("Bright blue")
team1.Parent = Teams
local team2 = Instance.new("Team")
team2.Name = "Checkpoint 2"
team2.AutoAssignable = false
team2.TeamColor = BrickColor.new("Bright green")
team2.Parent = Teams
local team3 = Instance.new("Team")
team3.Name = "Checkpoint 2"
team3.AutoAssignable = false
team3.TeamColor = BrickColor.new("Bright red")
team3.Parent = Teams
-- create spawns
local startSpawn = Instance.new("SpawnLocation")
startSpawn.Anchored = true
startSpawn.Size = Vector3.new(5, 1, 5)
startSpawn.Neutral = false
startSpawn.AllowTeamChangeOnTouch = false
startSpawn.TeamColor = startTeam.TeamColor
startSpawn.BrickColor = startTeam.TeamColor
startSpawn.Parent = game.Workspace
local team1Spawn = Instance.new("SpawnLocation")
team1Spawn.Anchored = true
team1Spawn.Size = Vector3.new(5, 1, 5)
team1Spawn.Neutral = false
team1Spawn.AllowTeamChangeOnTouch = true
team1Spawn.TeamColor = team1.TeamColor
team1Spawn.BrickColor = team1.TeamColor
team1Spawn.Parent = game.Workspace
local team2Spawn = Instance.new("SpawnLocation")
team2Spawn.Anchored = true
team2Spawn.Size = Vector3.new(5, 1, 5)
team2Spawn.Neutral = false
team2Spawn.AllowTeamChangeOnTouch = true
team2Spawn.TeamColor = team2.TeamColor
team2Spawn.BrickColor = team2.TeamColor
team2Spawn.Parent = game.Workspace
local team3Spawn = Instance.new("SpawnLocation")
team3Spawn.Anchored = true
team3Spawn.Size = Vector3.new(5, 1, 5)
team3Spawn.Neutral = false
team3Spawn.AllowTeamChangeOnTouch = true
team3Spawn.TeamColor = team3.TeamColor
team3Spawn.BrickColor = team3.TeamColor
team3Spawn.Parent = game.Workspace
-- 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)

วิธีการ

อีเวนต์