Hi everyone it’s my first post here on the dev forum I’m so happy to join the community. Please note that I am an amateur scripter so my scripts are not perfect.
Anyways I have been trying to make an extremely simple pathfinding humanoid script for my Roblox game. A couple of days ago it worked completely fine but now it’s not working. I’ve tried to fix it by changing the destination to a different part and he still would not move.
local humanoid = script.Parent.Humanoid
local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent
local destination = game.Workspace.Destination.Position
--path maker
local path = pathfindingService:CreatePath()
--compute path
path:ComputeAsync(body.Position, destination)
-- get waypoints
local waypoints = path:GetWaypoints()
for k, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoints.Position)
if waypoints.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid.MoveToFinished:Wait()
end```
My script location.
![Devforumpost|649x409](upload://mi8w59osY2T1zQE1ZT1vyyPkYWg.png)
Hmm, it did not seem to work but I got a new error “Position is not a valid member of model.” I’m honestly not sure what’s up with this error I tried moving my script around but it did not change anything. The error is on line 12 and I think it’s having trouble finding my “Body” which is referring to the humanoid root part and because I put in body.Position wouldn’t it try to find the humanoid root part position?
A Model does not have the property position try replacing the destination variable with this:
local destination = script.Parent:WaitForChild("HumanoidRootPart") or script.Parent.PrimaryPart
Its possible that the model loaded in before its children. Using :WaitForChild is a better alternative to :FindFirstChild as it waits for the humanoid root part to be loaded in