我正在做一个过场动画,我有兴趣在某个部分被触摸时通过脚本移动人形机器人。
这是我的代码:
game.Workspace.SpawnLocation.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
humanoid:MoveTo(Vector3.new(41.958, 4.264, 66.435))
end)
但是脚本没有运行。
答案 0 :(得分:0)
马上我就看到您确实没有包含一个结尾来标记脚本的结尾。此脚本有时会失败,因此我建议您添加 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)