lua - 通过触摸事件移动人形机器人的问题
问题描述
我正在做一个过场动画,并且我有兴趣在触摸某个部分时通过脚本移动人形。
这是我的代码:
game.Workspace.SpawnLocation.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
humanoid:MoveTo(Vector3.new(41.958, 4.264, 66.435))
end)
但是脚本没有运行。
解决方案
马上我看到你没有包括结束来标记脚本的结束。这个脚本有时会失败,所以我建议你添加 FindFirstChild()。
固定版本:
workspace.SpawnLocation.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if not humanoid then
return
end
humanoid:MoveTo(Vector3.new(41.958, 4.264, 66.435))
end)
推荐阅读
- angular - 用 Typescript 中另一个 observable 的结果填充 observable 中的字段
- rxjs - 从 Observable 重放主题(发出所有以前的事件)
- android - 有没有办法在android中压缩png文件?
- java - 从不同的类添加 JPanel
- ruby-on-rails - 如何使用 Devise gem 在 Ruby on Rails 中保存 has_many 关系?
- mysql - MYSQL ORDER BY strtotime(column) ASC 可能吗?
- pact - 如何在我的 ProviderService 中启动模拟服务器并调用 Web 服务?
- javascript - 为什么我的第二个 if 语句在我的第一个 if 语句为真之后连续运行 2 次?
- symfony - 为 Symfony 设置 Apache 虚拟主机
- itext - 如何用希伯来语生成 PDF?目前生成的 PDF 为空