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
4 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.

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)

Thanks all replies appreciated.

1 answer

Log in to vote
0
Answered by 4 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 — 4y
Ad

Answer this question