パーツに触れたら別のゲームに移動させる方法です。
- Workspace に Part を1つ追加します。
- Part に Script を追加します。
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local part = script.Parent
local placeId = 移動先のゲーム番号
part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
TeleportService:Teleport(placeId, player)
end
end)
他プレースへの移動
ゲーム内の異なる場所(プレース)へ複数人のプレイヤーを移動する方法です。TeleportAsync を使用します。
以下のプログラムはRoblox公式(https://create.roblox.com/docs/ja-jp/projects/teleporting)から引用させていただきました。
SafeTeleportのパラメータ
- placeId プレースのID
- players 転送したいプレイヤー({ Player1,Player2,Player3…} と配列で指定)
- options 渡したいデータ(テーブルで指定)
local TeleportService = game:GetService("TeleportService")
local ATTEMPT_LIMIT = 5
local RETRY_DELAY = 1
local FLOOD_DELAY = 15
local function SafeTeleport(placeId, players, options)
local attemptIndex = 0
local success, result -- define pcall results outside of loop so results can be reported later on
repeat
success, result = pcall(function()
return TeleportService:TeleportAsync(placeId, players, options) -- teleport the user in a protected call to prevent erroring
end)
attemptIndex += 1
if not success then
task.wait(RETRY_DELAY)
end
until success or attemptIndex == ATTEMPT_LIMIT -- stop trying to teleport if call was successful, or if retry limit has been reached
if not success then
warn(result) -- print the failure reason to output
end
return success, result
end
local function handleFailedTeleport(player, teleportResult, errorMessage, targetPlaceId, teleportOptions)
if teleportResult == Enum.TeleportResult.Flooded then
task.wait(FLOOD_DELAY)
elseif teleportResult == Enum.TeleportResult.Failure then
task.wait(RETRY_DELAY)
else
-- if the teleport is invalid, report the error instead of retrying
error(("Invalid teleport [%s]: %s"):format(teleportResult.Name, errorMessage))
end
SafeTeleport(targetPlaceId, {player}, teleportOptions)
end
TeleportService.TeleportInitFailed:Connect(handleFailedTeleport)
return SafeTeleport
こんにちは。
プレースに関して質問させてください。
複数のプレースが存在するゲームで、開始プレースの変更はどうすればいいですか?
クリエーターハブ -> 該当ゲーム -> 環境設定/プレース の部分でできそうな気がするのですが、そこからはできませんでした。
「バーチャル空間から削除」「アップデートするにはサーバを再起動」のコマンドはありました。サーバの再起動も試したのですが、特に変わらずでした。
よろしくお願いいたします。
確かに開始プレースを変更するようなところがありませんね。
プレースへの上書きは出きるので、それを利用するのがベストだと思います。
お返事ありがとうございます。
なるほど、現時点では開始プレースの変更はできなそうなんですね。chatGPT に 日を跨いで複数回聞いても、できるようなことを言っていたので、できるのかなと思っておりました。
ちなみに、プレースの上書きなどはどこからできますでしょうか?
Studio をいじっているときに、一回だけそのページに行けたのですが、以降どこから行けるかが全然わからなくなってしまいました。
開始プレースにしたいものを開き、ファイルの「名前を付けてRobloxに公開」を実行します。
次に保存先のゲームを選択するとプレースの一覧が表示されますので、開始プレースを選択すれば上書きできます。
返信ありがとうございます
現在の開始プレースを複製しておく、プレースの上書きなので付随する説明分やスクリーンショットなどは元のままなので、一見すると上書きされているのかわからなかった、など、注意点はありましたが、無事できました。