Task API
Every command's run receives a task, created fresh for every target. It handles cleanup, persistence and live updates so you don't have to. See Custom Commands for writing the commands themselves. Members are tagged Server, Shared (works in client commands too) or Client.
Methods¶
task:keep Server¶
task:keep(persistence: Persistence?)
Keeps the task alive after run returns, as tasks are otherwise destroyed immediately. Your options are "UntilTargetRespawns", "UntilTargetLeaves", "UntilCallerRespawns", "UntilCallerLeaves" and "Indefinitely".
task:getArg Server¶
task:getArg(name: string, default: any?): any
Reads a command argument by name. When the player didn't provide one, it falls back to default and remembers it.
task:setArg Server¶
task:setArg(name: string, value: any)
Sets a command argument by name, so later reads and any live prompt pick up the new value.
task:buff Server¶
task:buff(player: Player, group: string, callback: (hasEnded: boolean, original: any) -> any)
Changes something and restores it automatically when the task ends. Your callback applies the change and returns the original value, then runs again with hasEnded = true to put it back. Buffs from different tasks stack safely. Call task:updateBuffs(player, group) to re-apply after an argument changes, as the ;speed command does.
task:redo Server¶
task:redo(player: Player?, callback: () -> ())
Calls callback immediately, then again every time the player respawns while the task is alive. Handy for effects that would otherwise vanish on death.
task:bindPrompt Server¶
task:bindPrompt(config)
Attaches an interactive prompt to the command, like the slider on ;speed. Give it the args to expose and an onChange handler, then react (usually with task:updateBuffs) as the caller adjusts them.
task.client:run Server¶
task.client:run(player: Player?, ...)
task.client:runAll(...)
task.client:runOthers(originPlayer: Player, ...)
task.client:runNearby(originPlayer: Player?, radius: number, ...)
Invokes your matching client command on players' devices, passing any extra arguments through. run targets one player, runAll everyone, runOthers everyone but the origin, and runNearby those within radius studs. See client commands.
task:tween Shared¶
task:tween(instance: Instance, tweenInfo: TweenInfo, properties: {[string]: any}): Tween
Plays a tween that's cleaned up with the task, so it never outlives the command.
task:createSound Shared¶
task:createSound(soundType: SoundType?): Sound
Creates a Sound owned and cleaned up by the task, ready to play feedback or effects.
task:onEnded Shared¶
task:onEnded(callback: () -> ())
Runs callback every time the task ends, including a temporary deactivation.
task:onEndedForGood Shared¶
task:onEndedForGood(callback: () -> ())
Runs callback only when the task is destroyed for good, not when it's temporarily deactivated.
Scheduling Shared¶
task.spawn(callback: () -> ())
task.defer(callback: () -> ())
task.delay(seconds: number, callback: (() -> ())?)
task.wait(seconds: number?)
task.iterate(count: number, callback: (index: number) -> ())
task.loop(callback: (stop: () -> (), index: number) -> ())
Task-aware versions of Roblox's task scheduling. Each keeps the command alive while the work runs and stops cleanly when the task ends, so you never leave a loop or delayed call running after ;un.
task.server:replicate Client¶
task.server:replicate(...)
The client-side counterpart to task.client:run. Call it from a client command to send values back to the server, where they arrive on the same task.
Properties¶
task.target Server¶
task.target: Player?
The player the command is running on, or nil when it targets no one. task.targetUserId holds the id, which is set even when they're offline.
task.caller Server¶
task.caller: Player?
The player who ran the command, or nil when the server ran it. task.callerUserId holds the id.
task.janitor Shared¶
task.janitor:add(item): typeof(item)
A cleanup bag. Register instances, connections or functions and everything added is destroyed when the task ends, which is what makes ;unspeed and command groups work without any teardown code.
task.isActive Shared¶
task.isActive: boolean
true while the task is running, false once it starts ending. Check it inside long loops so your effect stops promptly on ;un.