在遊戲過程中找到朋友可能會很具挑戰性。SpawnWithFriends 開發者模組 自動將重生的玩家移動到遊戲中某位朋友的附近。此模組還可以配置為按命令傳送玩家,而不是自動傳送。
模組使用
安裝
在體驗中使用 SpawnWithFriends 模組:
從 Studio 的 視窗 菜單或 首頁 標籤工具列,打開 工具箱,並選擇 創作者商店 標籤。

確保選擇了 模型 排序,然後點擊 查看所有 按鈕以查看 類別。

找到並點擊 包 磚。
找到 與好友一起重生 模組並點擊它,或將其拖放到 3D 視圖中。

在 檢視器 窗口中,將整個 SpawnWithFriends 模型移動到 ReplicatedStorage。在運行該體驗後,模組將開始運行。
受限重生區域
此模組可能會導致玩家重生在受限區域,如 VIP 房間、僅限進入的空間等。為了防止玩家傳送到這些區域:
使用不可見的 Anchored 塊填滿受限區域。確保所有塊的 CanCollide、 CanTouch 和 CanQuery 都已 禁用。

填滿整個監獄房間的區塊,以防止玩家重生進入內部 使用每個區塊屬性的 標籤 區域,應用標籤 RestrictedSpawnArea 以便 CollectionService 能檢測到它們。
將以下代碼粘貼到 ServerScriptService 中的一個 Script 中。
Scriptlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local CollectionService = game:GetService("CollectionService")local SpawnWithFriends = require(ReplicatedStorage.SpawnWithFriends)local function validator(playerToTeleport, destinationPlayer, teleportationPoint)-- 遍歷所有標記的部分for _, area in CollectionService:GetTagged("RestrictedSpawnArea") dolocal relativePosition = area.CFrame:PointToObjectSpace(teleportationPoint.Position)local size = area.Sizelocal inXBounds = relativePosition.X < size.X / 2 and relativePosition.X > -size.X / 2local inZBounds = relativePosition.Z < size.Z / 2 and relativePosition.Z > -size.Z / 2if inXBounds and inZBounds thenreturn false -- 重生目的地在受限區域內;中止傳送endendreturn true -- 重生目的地不與任何受限區域重疊;進行傳送endSpawnWithFriends.setTeleportationValidator(validator)
API 參考
功能
configure
configure(config: table)
通過 config 表中的以下鍵/值來覆蓋默認配置選項。此函數只能從 Script 中調用。
| 鍵 | 描述 | 默認值 |
|---|---|---|
| teleportToFriendOnRespawn | 如果設置為 false,則只有通過 teleportToRandomFriend 來手動傳送到好友。 | true |
| teleportDistance | 玩家之間應該相距的重生距離,以 studs 為單位。 | 5 |
| maxCharacterVelocity | 移動速度快於此值的角色將不會被選為傳送候選者,例如那些在移動的載具中。 | 48 |
| bypassFriendshipCheck | 如果設置為 true,所有 玩家都將成為傳送候選者,而不僅僅是好友。 | false |
| showLogs | 是否顯示日誌消息在輸出中。 | false |
Scriptlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local SpawnWithFriends = require(ReplicatedStorage.SpawnWithFriends)SpawnWithFriends.configure({teleportToFriendOnRespawn = true,teleportDistance = 5,maxCharacterVelocity = 48,bypassFriendshipCheck = false,showLogs = false})
teleportToRandomFriend
teleportToRandomFriend(playerToTeleport: Player): boolean
手動觸發將玩家傳送到他們的一位好友。返回一個布林值,指示傳送是否成功;傳送失敗可能是因為伺服器中沒有好友或無法找到無障礙的傳送點。此函數只能從 Script 中調用。
setTeleportationValidator
setTeleportationValidator(validator: function)
允許您通過連接驗證器回調功能來執行自定義的傳送前檢查。回調接受三個參數:
| 參數 | 描述 |
|---|---|
| playerToTeleport | 被傳送的 Player 的引用。 |
| destinationPlayer | 傳送到的目標 Player 的引用。 |
| teleportationPoint | CFrame,指向 playerToTeleport 將傳送到的位置。 |
此函數及其回調只能在 Script 中使用,回調返回一個布林值,指示是否應進行傳送。例如,以下驗證器函數中的 return 邏輯確保重生玩家和目的地玩家在同一隊伍中。
Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnWithFriends = require(ReplicatedStorage.SpawnWithFriends)
-- 只有在同一隊伍時才傳送玩家
local function validator(playerToTeleport, destinationPlayer, teleportationPoint)
return playerToTeleport.Team == destinationPlayer.Team
end
SpawnWithFriends.setTeleportationValidator(validator)