I've been experimenting with the pathfinding service to possibly use in my game. The code I have so far moves the player to the spot then does the next player once the player is in the spot;

local function mapPathFind(plr)
	game.ReplicatedStorage.False:FireAllClients()	
	for _, v in pairs(plr) do
		local character = v.Character
		local torso = character.HumanoidRootPart
		torso.CFrame = CFrame.new(workspace.Map:FindFirstChild("MapPathStart").Position + Vector3.new(0, 2, 0))
		local mapSeats = game.Workspace.Map:FindFirstChild("Seats"):GetChildren()
		local allseats = math.random(1, #mapSeats)
		local randomseat = mapSeats[allseats]
		if randomseat and torso then
			table.remove(mapSeats, allseats)
		end			
		local pathService = game:GetService("PathfindingService")
		local path = pathService:ComputeSmoothPathAsync(game.Workspace.Map:FindFirstChild("MapPathStart").Position, randomseat.Position, 300)		
		local movement = path:GetPointCoordinates()
		
		for i, point in ipairs(movement) do
			character.Humanoid:MoveTo(point)
			repeat
				local distance = (point - character.HumanoidRootPart.Position).magnitude
				wait()
			until distance < 3
		end
	end
end
	
mapPathFind(game.Players:GetPlayers())

But as the question suggests, I want to move all players at once not 1 by 1.

How would I do that?

Edit: Line 2 is a remove event that disables the player to move their player.

1 comment

1

I would move the for _,v in pairs(game.Players:GetChildren()) do to outside the function along with the FireAllClients and then just do spawn(function() mapPathFind(v) end) inside of the for loop