Run a Luau snippet repeatedly with a delay, collecting results
run-loopExecute a Luau snippet repeatedly with configurable delays in one round trip, capturing each iteration's return to poll changing values or retry flaky operations.
Instructions
Run a Luau snippet iterations times in a single round trip, waiting delayMs between iterations, and collect what each run produced. Use this to poll a value over time (e.g. read a Humanoid's Health every 200ms for 20 iterations to watch it change), to retry a flaky operation, or to drive a short repeated action and see the outcome of each pass — all without paying a tool round trip per iteration. The code is COMPILED ONCE (a syntax error returns { error } and nothing runs); each iteration is executed inside its own pcall so a runtime error in one pass is recorded and the loop continues. When collectReturns is true the FIRST return value of each run is captured via __encVal (Instances become their full path, tables/functions become a stable string), giving an ordered series you can compare across iterations. The whole loop runs synchronously in-client, so total time is roughly iterations * delayMs — keep that under the tool timeout. Requires loadstring; uses task.wait for the delay (falls back to wait). Returns { iterations, results, errorCount, errors } or { error }. Signature: { code: string, iterations: any?, delayMs: any?, collectReturns: any?, threadContext: number? }. Phase: act; cost=high; idempotency=contextual-write. Requires: active-client, explicit-mutation-approval, validated-source. Produces: operation-receipt. Verify with: assert-state. Safety: MUTATING; executes caller-selected behavior in the live client. On failure: inspect tool-schema for exact fields, defaults, constraints, and an invocation example.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The Luau snippet to run each iteration. Compiled once, then executed every pass. To capture a value per iteration, `return` it (only the first return value is collected when collectReturns is true). | |
| delayMs | No | Milliseconds to wait between iterations via task.wait (default 0 = yield minimally each pass). Use e.g. 200 to sample a value five times a second. There is no wait after the final iteration. | |
| iterations | No | How many times to run the snippet (default 5, clamped 1..1000). Combined with delayMs this determines total wall-clock time, so keep iterations * delayMs comfortably under the request timeout. | |
| threadContext | No | Optional Roblox thread identity for this call; omit it to use the server default. | |
| collectReturns | No | When true (default), capture the FIRST return value of each iteration into `results` (encoded as a serializable scalar/string). Set false to skip capture when the snippet returns nothing useful or large values you do not want echoed back. |