在游戏中找到朋友可能会很有挑战性。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 |
local 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 的引用,playerToTeleport 正在传送到该玩家。 |
| teleportationPoint | CFrame,表示 playerToTeleport 正在传送到的位置。 |
此函数及其回调只能在 Script 中使用,回调返回一个布尔值,指示是否应继续传送。例如,以下验证器函数中的 return 逻辑确保重生玩家和目标玩家在同一队伍中。
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)