Skip to content

Update

Callback ยท a function named Update that a script defines and the engine calls

Update(dt: number) -> ()

Update is a global function that the engine calls every frame with the seconds since the last frame. It runs after the frame's physics steps, in server and client scripts.

Effects

  • Declare Update as a global function before the script's first wait, such as task.wait or WaitFor; one declared later never runs.
  • An error ends that call only. 5 consecutive calls over the instruction or memory budget stop Update; see engine errors.

Example

-- Server script in a part: turn 90 degrees a second.
function Update(dt: number)
    local rot = self.Rotation
    if rot then
        self.Rotation = rot * Rotation.fromAxisAngle(Vector3.YAxis, 90 * dt)
    end
end