リスポーン地点(開始時の位置)を指定する
備忘録を兼ねて簡単にやり方を記載
手順1
「Workspace」の右の「+」をクリックして、『SpawnLocation』を作成
こいつが「SpawnLocation」です
手順2
「ServerScriptService」以下にスクリプトを作成(今回は「RespawnScript」としています)して書いていきます
(ServerScriptServiceにあるスクリプトは、ゲーム開始時に最初に実行されます)
RespawnScriptに以下のコードを記載します
local respawnDelay = 5 -- キャラクターが自動でリスポーンするかどうか -- falseならプレイヤーがゲームに参加する時を含め、各プレイヤーに対してPlayer:LoadCharacter関数が呼び出されるまで、プレイヤーキャラクターはスポーンしない game.Players.CharacterAutoLoads = false game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) -- find the humanoid, and detect when it dies local humanoid = character:FindFirstChild("Humanoid") if humanoid then humanoid.Died:Connect(function() wait(respawnDelay) player:LoadCharacter() end) end end) player:LoadCharacter() -- load the character for the first time end)
これで、リスポーン時に『SpawnLocation』からスタートするようになります!
今回のLua知識
lua言語で変数宣言時に「local」をつけるとローカル変数になります!
参考URL
https://developer.roblox.com/en-us/api-reference/function/Player/LoadCharacter