我正在尝试使用RemoteEvent通过服务器端的脚本将数据从一个LocalScript发送到另一个LocalScript。 第一个LocalScript在StarterCharacterScripts中,服务器端脚本在工作区中,第二个LocalScript在玩家的角色模型下。
我已经在每个函数中设置了print语句,以查看通信在哪里停止,并且当服务器在第二个LocalScript处触发该函数时,它似乎正在停止。 但是,我无法确定原因。
第一个LocalScript(StarterCharacterScripts)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = ReplicatedStorage:WaitForChild("CreatePartEvent")
local UserInputService=game:GetService("UserInputService")
local player=game.Players.LocalPlayer
UserInputService.InputBegan:Connect(function(input,gameProcessed)
if input.KeyCode==Enum.KeyCode.G then
createPartEvent:FireServer(251,226,11)
print("Bing!")
end
end)
服务器端脚本(工作区)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage)
createPartEvent.Name = "CreatePartEvent"
local fadePartEvent = Instance.new("RemoteEvent")
fadePartEvent.Parent=game.ReplicatedStorage
fadePartEvent.Name="FadePartEvent"
local function onCreatePartFired(player,red,green,blue)
print("Ting!" ,player,red,green,blue)
fadePartEvent:FireClient(player,red,green,blue)
end
createPartEvent.OnServerEvent:Connect(onCreatePartFired)
第二个LocalScript(播放器模型)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player=game.LocalPlayer
local fadePartEvent=ReplicatedStorage:WaitForChild("FadePartEvent")
fadePartEvent.Name="FadePartEvent"
local function onFadePartFired(player,red,green,blue)
print("Done!")
print(player,red,green,blue)
end
fadePartEvent.OnClientEvent:Connect(onFadePartFired)
如果代码正确运行,则输出应为:
Bing!
Ting! BusterTornado 251 226 11
Done! BusterTornado 251 226 11
但是,输出显示为:
Bing!
Ting! BusterTornado 251 226 11
这将表明该功能未达到第二个LocalScript。 我已经尝试过搜索,但到目前为止还没有找到任何答案。