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)
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.
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.
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().
Glad I was helpful. 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.