I want the coroutine loop to stop after a event is fired
local myLoop = coroutine.wrap(function()
local path:ComputeAsync(LHumanoidRootPart.Position,playerPosition)
if path.Status == Enum.PathStatus.Success then
for k, waypoint in pairs(path:GetWaypoints()) do
LHumanoid:MoveTo(waypoint.Position)
LHumanoid.MoveToFinished:Wait()
end
end
end)
myLoop()
game.ReplicatedStorage.RemoveEventFolder.SoldierEvents.OnServerEvent:Connect(function(player,troops,pos:CFrame)
myLoop.stop() -- where the loop would stop
end