【问题标题】:workspace.Tool.Handle.Script6: invalid argument#3(Vector3 Expected, Got Instance)workspace.Tool.Handle.Script6:无效参数#3(需要 Vector3,得到实例)
【发布时间】:2021-05-29 08:37:24
【问题描述】:

我正在尝试通过 remoteEvents 使部件在全局范围内跟随鼠标的位置。但是我收到了这个错误

workspace.Tool.Handle.Script6:无效参数#3(需要 Vector3,得到实例)

有什么问题吗?

本地脚本:

local tool = script.Parent.Parent
local rEvent = script.Parent.MoveToMousePos

tool.Equipped:Connect(function(mouse)
    mouse.Move:Connect(function()
    rEvent:FireServer(mouse.Hit.p)
end)
end)

脚本:

local tool = script.Parent.Parent
local rEvent = script.Parent.MoveToMousePos
local part = workspace.Test


rEvent.OnServerEvent:Connect(function(mousePos)
   part.Position = mousePos
end)

【问题讨论】:

    标签: roblox


    【解决方案1】:

    错误消息告诉您分配给part.Position 失败,因为提供的值不是Vector3,而是Instance。所以看看mousePos这个变量是怎么赋值的就是问题的线索了。

    每当客户端触发RemoteEvent 时,OnServerEvent 会提供发送消息的Player 实例,然后提供所有参数。所以目前,鼠标位置 被发送到服务器脚本,但在函数签名中被忽略,mousePos 变量被分配为调用RemoteEvent.FireServer() 的播放器。

    要修复您的代码,只需添加一个变量来说明调用 RemoteEvent 的播放器。

    rEvent.OnServerEvent:Connect(function(player, mousePos)
        part.Position = mousePos
    end)
    

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 2019-03-01
      • 1970-01-01
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      • 2020-04-20
      相关资源
      最近更新 更多