通过触摸事件移动人形机器人的问题
problem with moving the humanoid through a touched event
我正在做一个过场动画,我有兴趣在触摸某个部分时通过脚本移动人形生物。
这是我的代码:
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)
我正在做一个过场动画,我有兴趣在触摸某个部分时通过脚本移动人形生物。
这是我的代码:
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)