Lua 使用远程事件将roblox监狱的犯人保释出来并不';似乎工作不正常

Lua 使用远程事件将roblox监狱的犯人保释出来并不';似乎工作不正常,lua,roblox,Lua,Roblox,好吧,就这么定了。当你在我的游戏中被捕时,你会被送进监狱。要想逃出去,你必须得到保释。客户端向服务器发送一个请求以保护它们。除了这一部分,其他的部分似乎都能工作,但我相信它可能是客户端脚本。这个脚本有什么不正确的地方吗?我已经检查了它是否有任何明显的错误 local replicatedStorage = game:GetService('ReplicatedStorage') local createSystemMessage = replicatedStorage:WaitForChild(

好吧,就这么定了。当你在我的游戏中被捕时,你会被送进监狱。要想逃出去,你必须得到保释。客户端向服务器发送一个请求以保护它们。除了这一部分,其他的部分似乎都能工作,但我相信它可能是客户端脚本。这个脚本有什么不正确的地方吗?我已经检查了它是否有任何明显的错误

local replicatedStorage = game:GetService('ReplicatedStorage')
local createSystemMessage = replicatedStorage:WaitForChild('CreateSystemMessage')

game.ReplicatedStorage.Bail.OnServerEvent:Connect(function(Player,PlayerToBail)
        Player = game.Players:FindFirstChild(Player)

        local tab = nil
    for i,v in pairs(_G.GlobalData) do
        if v.Name == Player.Name then
            tab = v
        end
    end
    if PlayerToBail.Team == game.Teams:FindFirstChild("Criminal") then
        local Bounty = PlayerToBail.leaderstats.Bounty.Value * 2
     if tab.Bank <= Bounty then
        tab.Bank -= Bounty
            PlayerToBail.leaderstats.Bounty.Value = 0
            PlayerToBail.Prisoner.Value = false
            PlayerToBail.Team = game.Teams:FindFirstChild("Civilian")
            createSystemMessage:FireAllClients((Player.Name .. ' has Bailed ' .. PlayerToBail.Name), Color3.fromRGB(0, 250, 0))



end
end
    
end)

我相信问题发生在您传递给远程事件的参数上。 在客户端脚本中,将PlayerName作为参数传递。我假设这是玩家名字的字符串:

game.ReplicatedStorage.Bail:FireServer(PlayerName)
PlayerName实际上将被发送到参数“PlayerToBail”,我假设它应该是一个player对象。请记住,Roblox的RemoteEvents会自动传入作为第一个参数触发远程事件的玩家。因此,连接到远程事件的函数的“Player”参数是实际的Player对象,它具有触发远程事件的本地脚本

相反,我会触发如下远程事件:

game.ReplicatedStorage.Bail:FireServer()
由于您要保释的玩家将自动作为参数传递,因此无需向FireServer添加任何其他参数。此外,您还可以去掉服务器脚本中的“PlayerToBail”参数

另外请注意,服务器脚本中不需要有这行代码:

Player = game.Players:FindFirstChild(Player)
玩家已经在游戏中引用了一个对象。玩家。此外,Player是一个对象,而不是字符串。所以这是行不通的。您只需按原样使用播放器即可

有关远程事件的详细信息:


如果您仍然有问题,请随时跟进。

启动服务器时,它会自动给出一个参数,即发送服务器的玩家。因此,您不必拥有playerName部分,因为在player参数已经存在之后,您可以从中获取名称。

运行输出窗口时是否有任何错误?您是否已在服务器脚本中放入
print
语句?您说服务器脚本工作不正常,但当它运行时实际会发生什么?
Player = game.Players:FindFirstChild(Player)