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