🤖
【Roblox開発】SpawnLocationをチェックポイントにしてみた
はじめに
公式レファレンス
実装
オブジェクトの配置
チェックポイントSpawnLocation配置
SpawnLocation
を配置し名前を分かりやすく変更する。
全体配置
テストダメージPartの実装と配置
チェックポイントの機能を確認するためにプレイヤーを破壊するオブジェクトを配置しておきます。
まず、Part
を配置し色と大きさを変えます。
子にScriptを配置
そして以下のコードを書きこむ
local part = script.Parent
part.Touched:Connect(function(player)
local humanoid = player.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end)
コード
Teamを作成する
local Teams = game:GetService("Teams")
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 3"
team3.AutoAssignable = false
team3.TeamColor = BrickColor.new("Bright red")
team3.Parent = Teams
Teamのインスタンスの作成をし名前や色などを設定します。
AutoAssignable
をfalseに設定することで入室時に自動で振り分けられなくなります。
TeamをSapwnLocationに設定する
local checkPoint1SpawnLocation = workspace.CheckPoint1SpawnLocation
local checkPoint2SpawnLocation = workspace.CheckPoint2SpawnLocation
local checkPoint3SpawnLocation = workspace.CheckPoint3SpawnLocation
checkPoint1SpawnLocation.Neutral = false
checkPoint1SpawnLocation.AllowTeamChangeOnTouch = true
checkPoint1SpawnLocation.TeamColor = team1.TeamColor
checkPoint1SpawnLocation.BrickColor = team1.TeamColor
checkPoint2SpawnLocation.Neutral = false
checkPoint2SpawnLocation.AllowTeamChangeOnTouch = true
checkPoint2SpawnLocation.TeamColor = team2.TeamColor
checkPoint2SpawnLocation.BrickColor = team2.TeamColor
checkPoint3SpawnLocation.Neutral = false
checkPoint3SpawnLocation.AllowTeamChangeOnTouch = true
checkPoint3SpawnLocation.TeamColor = team3.TeamColor
checkPoint3SpawnLocation.BrickColor = team3.TeamColor
先ほど作成したTeamオブジェクトの設定をSpawnLocationのチームカラーを代入することでそのSpawnLocationが指定のチーム専用になります。
そして、AllowTeamChangeOnTouch
をtureにする事でこのSpawnLocationに触れることでそれが指定してるチームに変更させることができます。
全体コード
local Teams = game:GetService("Teams")
local checkPoint1SpawnLocation = workspace.CheckPoint1SpawnLocation
local checkPoint2SpawnLocation = workspace.CheckPoint2SpawnLocation
local checkPoint3SpawnLocation = workspace.CheckPoint3SpawnLocation
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 3"
team3.AutoAssignable = false
team3.TeamColor = BrickColor.new("Bright red")
team3.Parent = Teams
checkPoint1SpawnLocation.Neutral = false
checkPoint1SpawnLocation.AllowTeamChangeOnTouch = true
checkPoint1SpawnLocation.TeamColor = team1.TeamColor
checkPoint1SpawnLocation.BrickColor = team1.TeamColor
checkPoint2SpawnLocation.Neutral = false
checkPoint2SpawnLocation.AllowTeamChangeOnTouch = true
checkPoint2SpawnLocation.TeamColor = team2.TeamColor
checkPoint2SpawnLocation.BrickColor = team2.TeamColor
checkPoint3SpawnLocation.Neutral = false
checkPoint3SpawnLocation.AllowTeamChangeOnTouch = true
checkPoint3SpawnLocation.TeamColor = team3.TeamColor
checkPoint3SpawnLocation.BrickColor = team3.TeamColor
実行
Discussion