与朋友一起重生

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

在游戏中找到朋友可能会很有挑战性。SpawnWithFriends 开发者模块 会自动将重生的玩家移动到游戏中某个朋友附近。该模块也可以配置为在命令下传送玩家,而不是自动传送。

模块使用

安装

要在游戏中使用 SpawnWithFriends 模块:

  1. 从 Studio 的 窗口 菜单或 主页 选项卡工具栏中,打开 工具箱 并选择 创作者商店 选项卡。

  2. 确保选择了 模型 排序,然后点击 查看所有 按钮以查看 类别

  3. 找到并点击 瓦片。

  4. 找到 与朋友一起重生 模块并点击它,或将其拖放到 3D 视图中。

  5. 资源管理器 窗口中,将整个 SpawnWithFriends 模型移动到 ReplicatedStorage。运行游戏时,该模块将开始运行。

受限重生区域

该模块可能会导致玩家在受限区域(如 VIP 房间、仅限访问的空间等)重生。为了防止玩家传送到这些区域:

  1. 用不可见的 Anchored 块填充受限区域。确保所有块的 CanCollideCanTouchCanQuery 都被 禁用

    填充整个监狱房间的块,以防止玩家在内部重生
  2. 使用每个块属性的 标签 部分,应用标签 RestrictedSpawnArea 以便 CollectionService 检测到它们。

  3. 将以下代码粘贴到 ServerScriptService 中的 Script

    Script
    local 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") do
    local relativePosition = area.CFrame:PointToObjectSpace(teleportationPoint.Position)
    local size = area.Size
    local inXBounds = relativePosition.X < size.X / 2 and relativePosition.X > -size.X / 2
    local inZBounds = relativePosition.Z < size.Z / 2 and relativePosition.Z > -size.Z / 2
    if inXBounds and inZBounds then
    return false -- 重生目标在受限区域内;中止传送
    end
    end
    return true -- 重生目标不与任何受限区域重叠;继续传送
    end
    SpawnWithFriends.setTeleportationValidator(validator)

API 参考

函数

configure

configure(config: table)

通过 config 表中的以下键/值覆盖默认配置选项。此函数只能从 Script 中调用。

描述默认值
teleportToFriendOnRespawn如果设置为 false,则传送到朋友只会通过 teleportToRandomFriend 手动进行。true
teleportDistance玩家之间应相距多远,以 studs 为单位测量。5
maxCharacterVelocity移动速度超过此值的角色将不会被选为传送候选者,例如在移动车辆中的角色。48
bypassFriendshipCheck如果设置为 true,所有 玩家都将成为传送候选者,而不仅仅是朋友。false
showLogs是否在输出中显示日志消息。false
Script
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 正在传送到该玩家。
teleportationPointCFrame,表示 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)
©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。