Recently I’ve been trying to develop a script for moving multiple units from point A to point B, but, instead of doing what I ordered them to, they pace back and fourth for no good reason. Not sure if its something wrong with my script or roblox, at this point I might just do whatever A* is, but I don’t know how or why.
Here’s my code:
function RunCollectionMove(finalPosition,unit,FaceDirection)
spawn(function()
unit.HumanoidRootPart:SetNetworkOwner(nil)
local unitPath = PathfindingService:CreatePath()
unitPath:ComputeAsync(unit.HumanoidRootPart.Position, finalPosition)
wait(math.random(100,200)/100)
if unitPath.Status == Enum.PathStatus.Success then
local waypoints = unitPath:GetWaypoints()
for i, v in pairs (waypoints) do
unit.Humanoid:MoveTo(v.Position)
unit.Humanoid.MoveToFinished:Wait()
if v.Action == Enum.PathWaypointAction.Jump then
unit.Humanoid.Jump = true
end
if (waypoints[#waypoints].Position - finalPosition).magnitude > 15 then
break
end
end
end
wait(math.random(100,500)/100)
local info = TweenInfo.new(2,Enum.EasingStyle.Sine)
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = unit:GetPrimaryPartCFrame()
CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
unit:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local Angle = FaceDirection
local Spin = TweenService:Create(CFrameValue, info, {Value = (Angle - Angle.Position) + unit.HumanoidRootPart.Position})
Spin:Play()
Spin.Completed:Connect(function()
Tighten(unit)
end)
end)
end
Does anyone know how to fix this?