Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Pathing script not moving character?

I was trying to make a pathing script when it just didn't move. There are no errors.

local PathFindigService = game:GetService("PathfindingService")

local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")

local path = PathFindigService:CreatePath()
path:ComputeAsync(torso.position, game.Workspace.Part.Position)
local waypoints = path:GetWaypoints()

for i, waypoint in pairs(waypoints) do
	human:MoveTo(waypoint.Position)
	human.MoveToFinished:Wait(2)
end

1 comment

1

I would use HumanoidRootPart instead of torso, r15 models don't have a torso.

3 answers

I agree with what @cmgtotalyawesome said. R15 models have a "LowerTorso" and an "UpperTorso" while R6 models just have "Torso" so that is probably messing up your code. Every r6 and r15 have a HumanoidRootPart though. But the main problem I see here is, you say

human.MoveToFinished:Wait(2)

That number 2 is unnecessary, and it is messing up the code. I think you meant to say

human.MoveToFinished:Wait()
wait(2)

which waits until the move has finished, then waits 2 more seconds. Or you just want

human.MoveToFinished:Wait()

which just waits until the move has finished to continue the loop.

If that doesn't work then make sure that the NPC or model you are moving is not anchored (none of the limbs should be anchored)

hope this helps

4 comments

1

Unfortunatly this hasn't helped I was already using r6 charaters and the wait function change didn't work. anything else

0

Did you check if the model was unanchored

0

yes sorry for not repling

0

Thats okay, I tried using your script with a Dummy and everything seemed to be working fine? ( https://vimeo.com/543342884 ) I do not think it is the script, maybe you messed something up with the character?

Your using a torso to move, But the torso doesn't make you move, This is something in R6, R15, and rthro called a HumanoidRootPart it's basically a way to show Roblox where you are and it can move you so try this script.

local PathFindigService = game:GetService("PathfindingService")

local human = script.Parent:WaitForChild("Humanoid")
local rootPart = script.Parent:WaitForChild("HumanoidRootPart")

local path = PathFindigService:CreatePath()
path:ComputeAsync(rootPart.position, game.Workspace.Part.Position)
local waypoints = path:GetWaypoints()

for i, waypoint in pairs(waypoints) do
    human:MoveTo(waypoint.Position)
    human.MoveToFinished:Wait(2)
end
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		local torso = chr:WaitForChild("Torso")
		local human = chr:WaitForChild("Humanoid")
		local pfs = game:GetService("PathfindingService")
		local ctorso = script.Parent:WaitForChild("Torso")
		local chuman = script.Parent:WaitForChild("Humanoid")
		local path = pfs:CreatePath()
		path:ComputeAsync(ctorso.Position, torso.Position)
		
		while true do
			chuman:MoveTo(torso.Position)
			wait(0.000001)
		end
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.