Npc Not Moving To Waypoints

  1. What do you want to achieve? Keep it simple and clear!

I want the script to spawn and make the npc move to the waypoints. Once a part in workspace is touched (A different script removes the part once it is touched) There are no errors in the output(I am extremely new to scripting btw)

  1. What is the issue? Include screenshots / videos if possible!

My script spawns the npc but doesn’t destroy it and nor does it move to the waypoints.

Screenshot 2024-04-30 113046

local Npc = game.ReplicatedStorage.HallwayWisp:Clone()

local LabDetector = game.Workspace.EnterLabDetector

local EnterSound = Instance.new("Sound")

local PartsFound = game.ReplicatedStorage.Objectives.Parts.PartsFound

EnterSound.Parent = game.Workspace
EnterSound.SoundId = "rbxassetid://137308014"

LabDetector.Touched:Connect(function()
	
	wait(7)

	while true do 
	
		EnterSound:Play()
		wait(3.5)
		Npc.Parent = game.Workspace
		Npc.Position = Vector3.new(-396.6, 0.463, 962.75)
		
		Npc.Humanoid:MoveTo(game.Workspace.Waypoint1)
		Npc.Humanoid.MoveToFinished:Wait()
		
		Npc.Humanoid:MoveTo(game.Workspace.Waypoint1)
		Npc.Humanoid.MoveToFinished:Wait()
		
		Npc:Destroy()
		wait(6)
		
		if PartsFound.Value == 5 then
			break
		end
	end

end)

Note: The script is in ServerScriptService
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have been troubleshooting for a while and looked through multiple forum posts and tutorials but couldn’t find the answer.

I would greatly appreciate anyone who could help, and thank you for reading.

1 Like

You are passing an Instance to :MoveTo() but it only accepts Vector3 (for the first argument), try changing your script to this:

local PartsFound = game.ReplicatedStorage.Objectives.Parts.PartsFound

EnterSound.Parent = game.Workspace
EnterSound.SoundId = "rbxassetid://137308014"

LabDetector.Touched:Connect(function()
	
	wait(7)

	while true do 
	
		EnterSound:Play()
		wait(3.5)
		Npc.Parent = game.Workspace
		Npc:PivotTo(CFrame.new(-396.6, 0.463, 962.75))
		
		Npc.Humanoid:MoveTo(game.Workspace.Waypoint1.Position)
		Npc.Humanoid.MoveToFinished:Wait()
		
		Npc.Humanoid:MoveTo(game.Workspace.Waypoint1.Position)
		Npc.Humanoid.MoveToFinished:Wait()
		
		Npc:Destroy()
		wait(6)
		
		if PartsFound.Value == 5 then
			break
		end
	end

end)

Note: The waypoints have to be a base part, if it’s a model use :GetPivot().Position instead. You may also need to get the humanoid using :FindFirstChild().

3 Likes

It didn’t work, the npc just stays still but thank you for helping :slight_smile:

Try debugging using print statements to see if it reaches the :MoveTo() function. I’m in school rn so I might reply a little bit late.

1 Like

I made a mistake inputting the code you gave me lol it works now tysm it helped me alot

Glad I was helpful. :smile: By the way, you CAN actually pass a base part as the second argument. What this will do is still go to the position but if the base part moves then it will go to its new position instead. Just wanted to clear that up.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.