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)