problem with moving the humanoid through a touched event

Viewed 53

I'm doing a cutscene and I'm interested into moving the humanoid through a script when a part is touched.

This is my code:

game.Workspace.SpawnLocation.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
humanoid:MoveTo(Vector3.new(41.958, 4.264, 66.435))
end)

However the script is not running.

1 Answers

Right off the bat I see that you did NOT include a end to mark the end of the script. This script will sometimes fail, so I recommend you add FindFirstChild().

Fixed Version:

   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)
Related