I am working on a a game that uses a mechanic with a delivery man for acquiring items. I ran into a problem that the npc is moving in breaks and just acts strange in general. In studio however they used to act entirely normal (At the end of the clip he does weird again). This is the part of the code that deals with the movement and pathfinding of the npc.
for i,j in pairs(workspace.workplaces:GetChildren()) do
if j.Owner.Value == plr then
local deliveryman = game.ServerStorage[“Delivery Man”]:Clone()
deliveryman.Parent = j
deliveryman:SetPrimaryPartCFrame(workspace.DeliveryManTarget.CFrame)
for i = 1,280 do
j.Conveyor.Box:SetPrimaryPartCFrame(j.Conveyor.Box:GetPrimaryPartCFrame()+Vector3.new(-.05,0,0))
wait()
end
local PathfindingService = game:GetService(“PathfindingService”)
local path = PathfindingService:CreatePath()
path:ComputeAsync(deliveryman.HumanoidRootPart.Position, j.Conveyor.ConveyorTarget.Position)
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
deliveryman.Humanoid:MoveTo(waypoint.Position)
deliveryman.Humanoid.MoveToFinished:Wait()
if waypoint.Action == Enum.PathWaypointAction.Jump then
deliveryman.Humanoid.Jump = true
end
end
wait(1)
j.Conveyor.Box:SetPrimaryPartCFrame(j.Conveyor.BoxTarget.CFrame)
path:ComputeAsync(deliveryman.HumanoidRootPart.Position,j.Box.BoxTarget.Position)
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
deliveryman.Humanoid:MoveTo(waypoint.Position)
deliveryman.Humanoid.MoveToFinished:Wait()
if waypoint.Action == Enum.PathWaypointAction.Jump then
deliveryman.Humanoid.Jump = true
end
end
if deliveryman ~= nil then
j.Box.Box.Transparency = 0
j.Box.Tape.Transparency = 0
j.Box.Tape.CanCollide = true
j.Box.Box.CanCollide = true
j.Box.Box.SurfaceGui.ImageLabel.Visible = true
j.Box.Box.ProximityPrompt.Enabled = true
local newitem = Instance.new(“Folder”,j.Box.Box.ProximityPrompt.Script)
local Class = Instance.new(“StringValue”,newitem)
Class.Name = “Class”
Class.Value = args[1]
local Item = Instance.new(“StringValue”,newitem)
Item.Name = “Item”
Item.Value = args[2]
end
path:ComputeAsync(deliveryman.HumanoidRootPart.Position, workspace.DeliveryManTarget.Position)
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
deliveryman.Humanoid:MoveTo(waypoint.Position)
deliveryman.Humanoid.MoveToFinished:Wait()
if waypoint.Action == Enum.PathWaypointAction.Jump then
deliveryman.Humanoid.Jump = true
end
end
if deliveryman ~= nil then
deliveryman:Destroy()
end
end
end
I have no clue what is causing this. I think it might have something to do with the MoveTo() timeout but I’m not really sure since I am new to the concept of coroutines.
robloxapp-20210216-0837593.wmv (8,0 MB) robloxapp-20210216-0839546.wmv (3,9 MB)