为什么脚本认为这个 Vector3 位置是一名球员?
我正在尝试完成游戏的枪支脚本,但我放弃了很多东西。这次,我想我可以完成剧本了。但是,当我检查输出时,它说我在应该使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 RemoteEvent.OnServerEvent 的文档。提供给连接的第一个参数始终是调用 RemoteEvent 的玩家:FireServer()。
例如:
因此,在您的情况下,即使变量名为
posofm
,由于它是列表中的第一个参数,因此它代表 Player 对象。并且鼠标的实际位置被忽略,因为函数中没有参数来存储它。因此,要解决此问题,您需要做的就是在连接中添加一个参数来代表玩家并正确标记您的参数:
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 :
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 :