如何让 ServerScript 等待 LocalScript 触发 RemoteEvent

问题描述 投票:0回答:1

我已经从 ROBLOX 开发者论坛搜索了大量论坛帖子来寻找任何答案,但我没有找到答案,所以我希望你能提供帮助。

基本上,我想让 ServerScript(位于 ServerScriptService)等待 LocalScript(位于 GUI 按钮中)以与用户选择的警察部门一起触发 RemoteEvent(使用 FireServer)。

我目前只有一个 GUI 按钮设置(前线警务)。 LocalScript 可以在下面找到;

本地脚本

local div = game.ReplicatedStorage.Events.divisionEvent

local button = script.Parent
local gui = script.Parent.Parent.Parent.Parent

button.MouseButton1Down:Connect(function()
    div:FireServer("Frontline")
    gui.Enabled = false
end)

TLDR - 我想知道是否可以让 ServerScript 等待 LocalScript 触发包含所需信息的 RemoveEvent。

我已经通过大约 50-60 个 Roblox 开发者论坛帖子进行了大量研究,但没有一个是;

  • 和我的问题一样。
  • 正确的解决方案。
  • 甚至与我的问题无关。
lua roblox luau roblox-studio
1个回答
0
投票

您想要在 Remote.OnServerEvent 上建立连接 我建议阅读here并尝试自己编写代码。这是一个很好的学习方式。

但是这是解决您问题的代码:

local div = game:GetService("ReplicatedStorage").Events.divisionEvent

div.OnServerEvent:Connect(function(Player, Team)
    --Player is the player instance who fired the remote (Assigned automatically by Roblox) Example: game:GetService("Players").Guest
    --The first argument given to :FireServer, for your case would be "Frontline"
end)
© www.soinside.com 2019 - 2024. All rights reserved.