You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FireServer()未触发Remote Event,玩家死亡数值修改失效求助

问题分析与修复方案

你遇到的核心问题是服务器脚本未正确定义关键变量,同时本地脚本的角色死亡监听逻辑存在复活后失效的隐患,另外还需确保相关实例存在。以下是具体修复:

问题点拆解

  • 服务器脚本里rs未赋值,导致无法定位RemoteEvent。
  • 本地脚本直接获取初始Character,玩家复活后新角色不会触发死亡监听。
  • 未确保InLobby BoolValue一定存在于玩家对象下。

修正后的本地脚本

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local plr = Players.LocalPlayer
local remoteEvent = ReplicatedStorage:WaitForChild("setPlayerInLobby")

local function bindDeathListener(char)
    local humanoid = char:WaitForChild("Humanoid")
    humanoid.Died:Connect(function()
        print('death')
        remoteEvent:FireServer()
        print('fired')
    end)
end

-- 处理已加载的角色
if plr.Character then
    bindDeathListener(plr.Character)
end
-- 监听后续角色生成(复活)
plr.CharacterAdded:Connect(bindDeathListener)

修正后的服务器脚本

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local remoteEvent = ReplicatedStorage:WaitForChild("setPlayerInLobby")

remoteEvent.OnServerEvent:Connect(function(plr)
    print("works i guess?")
    -- 检查并创建InLobby值
    local inLobby = plr:FindFirstChild("InLobby")
    if not inLobby then
        inLobby = Instance.new("BoolValue")
        inLobby.Name = "InLobby"
        inLobby.Parent = plr
    end
    inLobby.Value = true
end)

额外检查项

  1. 确认ReplicatedStorage中确实存在名为setPlayerInLobby的RemoteEvent实例。
  2. 确保本地脚本放在StarterPlayerScripts或StarterPack等正确的本地执行容器中。

内容的提问来源于stack exchange,提问作者random scripter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 00:55:19