为什么脚本认为这个 Vector3 位置是一名球员?

发布于 2025-01-11 00:49:17 字数 591 浏览 0 评论 0原文

我正在尝试完成游戏的枪支脚本,但我放弃了很多东西。这次,我想我可以完成剧本了。但是,当我检查输出时,它说我在应该使用 Vector3 时尝试使用实例。当我看到它时,我很快意识到脚本认为这是一个玩家。怎么了?

script.Parent.Shoot.OnServerEvent:Connect(function(posofm) --I am using a LocalScript to get the position of the mouse (mouse.Hit.Position)
    bullet = Instance.new("Part")
    bullet.Parent = workspace
    bullet.Size = Vector3.new(0.3,0.3,1)
    bullet.BrickColor = BrickColor.Yellow()
    bullet.Position = script.Parent.Handle.Position
    bullet.CFrame = CFrame.lookAt(bullet.Position,posofm)
    bullet.Velocity = bullet.CFrame.LookVector * 90
end)

I'm trying to finish a gun script for a game, and I have scrapped many things. This time, I thought I could finish the script. But then, when I checked output it said that I was trying to use an Instance when I should be using a Vector3. When I looked at it, I soon realized that the script thought it was a player. WHAT IS HAPPENING?

script.Parent.Shoot.OnServerEvent:Connect(function(posofm) --I am using a LocalScript to get the position of the mouse (mouse.Hit.Position)
    bullet = Instance.new("Part")
    bullet.Parent = workspace
    bullet.Size = Vector3.new(0.3,0.3,1)
    bullet.BrickColor = BrickColor.Yellow()
    bullet.Position = script.Parent.Handle.Position
    bullet.CFrame = CFrame.lookAt(bullet.Position,posofm)
    bullet.Velocity = bullet.CFrame.LookVector * 90
end)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

维持三分热 2025-01-18 00:49:17

查看 RemoteEvent.OnServerEvent 的文档。提供给连接的第一个参数始终是调用 RemoteEvent 的玩家:FireServer()

例如:

-- when a LocalScript calls FireServer :
event:FireServer(a, b, c)

-- the server Script receives :
event.OnServerEvent:Connect(function(player, a, b, c) ... end)

因此,在您的情况下,即使变量名为 posofm,由于它是列表中的第一个参数,因此它代表 Player 对象。并且鼠标的实际位置被忽略,因为函数中没有参数来存储它。

因此,要解决此问题,您需要做的就是在连接中添加一个参数来代表玩家并正确标记您的参数:

script.Parent.Shoot.OnServerEvent:Connect(function(player, posofm)

Take a look at the docs for RemoteEvent.OnServerEvent. The first argument provided to the connection is always the Player that called RemoteEvent:FireServer().

For example :

-- when a LocalScript calls FireServer :
event:FireServer(a, b, c)

-- the server Script receives :
event.OnServerEvent:Connect(function(player, a, b, c) ... end)

So in your case, even though the variable is named posofm, since it is the first argument in the list, it represents the Player object. And the actual position of the mouse is ignored because there's no argument in the function to store it.

So to fix it, all you need to do is add an argument in the connection to represent the player and properly label your arguments :

script.Parent.Shoot.OnServerEvent:Connect(function(player, posofm)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文