What this script does
Build a deterministic multi-slot hatch schedule from ids and durations supplied by your own server or Studio test.
- Best for
- Incubators, crafting queues, build slots, and other parallel timers in an experience you own.
- Language
- Luau
- Version
- 1.0.0
- Validation
- Luau runtime tested
Official Luau 0.735 parsing and strict analysis pass, and the module is covered by the pure-module runtime behavior harness.
Included behavior
- Earliest-slot scheduling
- Stable slot choice for equal times
- Finish-time helper
Install in the stated runtime
- 1Create a ModuleScript named HatchQueue.
- 2Paste the complete source and require it from a server or test Script in your own experience.
- 3Pass validated server-owned requests and treat returned timestamps as a plan until your own server commits the queue.
Minimal usage example
local HatchQueue = require(script.Parent.HatchQueue)
local schedule = HatchQueue.plan({
{ id = "egg-a", durationSeconds = 90 },
{ id = "egg-b", durationSeconds = 45 },
}, 2, os.time())
print(schedule[1].readyAt)Example inputs and result
- Supply
- Egg ids and durations, slot count, and a starting timestamp.
- Expect
- plan returns a proposed schedule with readyAt times; it does not hatch Eggs.
These notes explain the example above. Read the complete source for every exported function and edge case before integrating it.
Complete source
No hidden import, minified block, or shortened loader.
--!strict
-- MIT License. Plans hatch slots for an experience you own; it does not inspect or automate another game.
export type HatchRequest = { id: string, durationSeconds: number }
export type ScheduledHatch = { eggId: string, slot: number, startsAt: number, readyAt: number }
local HatchQueue = {}
function HatchQueue.plan(requests: { HatchRequest }, slotCount: number, startsAt: number?): { ScheduledHatch }
local slots = math.floor(slotCount)
assert(slots >= 1, "At least one hatch slot is required")
local origin = startsAt or 0
local availableAt: { number } = {}
for slot = 1, slots do availableAt[slot] = origin end
local schedule: { ScheduledHatch } = {}
for _, request in requests do
assert(request.id ~= "", "Egg id cannot be empty")
assert(request.durationSeconds >= 0, "Hatch duration must be non-negative")
local chosenSlot = 1
for slot = 2, slots do
if availableAt[slot] < availableAt[chosenSlot] then chosenSlot = slot end
end
local readyAt = availableAt[chosenSlot] + request.durationSeconds
table.insert(schedule, {
eggId = request.id,
slot = chosenSlot,
startsAt = availableAt[chosenSlot],
readyAt = readyAt,
})
availableAt[chosenSlot] = readyAt
end
return schedule
end
function HatchQueue.finishTime(schedule: { ScheduledHatch }): number
local latest = 0
for _, item in schedule do latest = math.max(latest, item.readyAt) end
return latest
end
return table.freeze(HatchQueue)
0489398dbf05c5f252b91d9ebedea615d524ea584cb41ce164c79cf3f7e9ea39Outside this script’s scope
- Start or inspect a live Steal An Egg hatch
- Click, collect, or claim anything for a player
Found a problem or a better approach?
Tell us what failed, what you expected, and whether the issue happened in the Luau CLI or Roblox Studio. Suggestions for clearer types, safer server checks, or a more useful API are welcome.