I want an npc to move to two parts one after another.
This is what the code looks like so far:
local dummy = script.Parent
local middle = game.Workspace.Spawn1Middle
local End = game.Workspace.Spawn1End
dummy.Humanoid:MoveTo(middle.Position)
--detect if humanoid touched, if so, go to the end position, otherwise keep walking
dummy.Humanoid:MoveTo(End.Position)
I don’t know how to detect when the npc touches the middle part.
I tried doing dummy.Humanoid:Touched but I didn’t know how to implement it.
local dummy = script.Parent
local middle = game.Workspace.Spawn1Middle
local End = game.Workspace.Spawn1End
dummy.Humanoid:MoveTo(middle.Position)
middle.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent.Name == dummy.Name then
dummy.Humanoid:MoveTo(End.Position)
end
end)
local dummy = script.Parent
local middle = game.Workspace.Spawn1Middle
local End = game.Workspace.Spawn1End
dummy.Humanoid:MoveTo(middle.Position)
if dummy.Humanoid.MoveToFinished(middle.Position) then
task.wait(1.5)
dummy.Humanoid:MoveTo(End.Position)
end
Instead of detecting if NPC have touched or no, you can wait for NPC to reach middle part. Here is the script anyways
local dummy = script.Parent
local middle = game.Workspace.Spawn1Middle
local End = game.Workspace.Spawn1End
local v1 = false
dummy.Humanoid:MoveTo(middle.Position)
spawn(function()
while wait(1) do
if (dummy.HumanoidRootPart.Position - middle.Position).Magnitude <= 10 then
v1 = true
end
end
end)
while not v1 do
wait()
end
dummy.Humanoid:MoveTo(End.Position)
MoveToFinished isn’t a method, but rather an event. An implemenation of this would be:
local dummy = script.Parent
local middle = game.Workspace.Spawn1Middle
local End = game.Workspace.Spawn1End
dummy.Humanoid:MoveTo(middle.Position)
dummy.Humanoid.MoveToFinished:Wait()
task.wait(1.5)
dummy.Humanoid:MoveTo(End.Position)