Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I get multiple students to move to a point at the same time?

Asked by
3132750 45
5 years ago

Hi, I'm trying to get students to each get a seat from a table with multiple seats. However, the current problem with my script is it waits for a student to get to their seat before summoning another player to a different seat. Here is my script so far. Note: students are not actual players, but ai.

01local destPos
02local dest
03local seatVal
04script.Parent.Parent.Parent.timeEvent.OnServerEvent:Connect(function(plr,cTime)
05    if cTime == "Lunch time" then
06for _, stu in pairs(script.Parent.Parent:GetChildren()) do
07if stu.Name == "ben" then
08for _, seat in pairs(script.Parent:GetChildren()) do
09        if seat.Name == "Seat" then
10            if seat.taken.Value == false then
11                seatVal = seat
12                destPos = seat.Position
13                dest = Vector3.new(destPos.X,destPos.Y,destPos.Z)
14            end
15        end
View all 43 lines...

Thanks all replies appreciated.

1 answer

Log in to vote
0
Answered by 5 years ago

local destPos local dest local seatVal script.Parent.Parent.Parent.timeEvent.OnServerEvent:Connect(function(plr,cTime) if cTime == "Lunch time" then for _, stu in pairs(script.Parent.Parent:GetChildren()) do if stu.Name == "ben" then for _, seat in pairs(script.Parent:GetChildren()) do if seat.Name == "Seat" then if seat.taken.Value == false then seatVal = seat destPos = seat.Position dest = Vector3.new(destPos.X,destPos.Y,destPos.Z) end end end

if dest ~= nil then local pathServ = game:GetService("PathfindingService") local path = pathServ:CreatePath() local student = stu local body = student:FindFirstChild("HumanoidRootPart") or student:FindFirstChild("Torso") local humanoid = student.Humanoid path:ComputeAsync(body.Position, dest) local waypoints = path:GetWaypoints() seatVal.taken.Value = true for k,waypoint in pairs(waypoints) do humanoid:MoveTo(waypoint.Position) if waypoint.Action == Enum.PathWaypointAction.Jump then humanoid:ChangeState(Enum.HumanoidStateType.Jumping) end humanoid.MoveToFinished:Wait() end else print("no dest found") script.Parent:MoveTo(dest) return("Done") end

end end end end)

0
Imagine copy and pasting a question.. Instead of an answer like you did last time a few days ago. 123nabilben123 499 — 5y
Ad

Answer this question