Scheduler

Events

RunService, UserInputService and mc.Events.

RunService

Frame events. All of them are signals.

EventFiresArguments
RunService.SteppedEvery frame, firsttime, dt
RunService.Tick20 times per second (fixed)0.05
RunService.HeartbeatEvery framedt
RunService.RenderSteppedEvery frame, lastdt

time is the scheduler time in seconds and dt is the frame time in seconds.

Tick catches up if frames are slow, up to 5 times in a frame. If more than a quarter of a second is owed, the extra time is thrown away.

RunService.Heartbeat:Connect(function(dt)
  -- runs every frame
end)

RunService.Tick:Connect(function()
  -- runs at a steady 20 Hz
end)

UserInputService

UserInputService.InputBegan

Fires when a key or mouse button goes down. The arguments are (input, gameProcessed).

UserInputService.InputEnded

Fires when a key or mouse button is released. Same arguments.

The input table has two fields:

FieldMeaning
KeyCodeThe key name as a string. Mouse buttons are "MouseLeft", "MouseRight", "MouseMiddle"
UserInputTypeThe same string for mouse buttons, or "Keyboard" for keys

gameProcessed is always false.

UserInputService.InputBegan:Connect(function(input)
  if input.KeyCode == "MouseRight" then
    print("right mouse down")
  end
end)

UserInputService:IsKeyDown(name)

Returns whether the key is currently held. It is written as a method call: UserInputService:IsKeyDown("MouseLeft").

mc.Events

Events for game and connection state. Same signal objects, shorter names.

EventSame asArguments
mc.Events.RenderRunService.RenderSteppeddt
mc.Events.HeartbeatRunService.Heartbeatdt
mc.Events.TickRunService.Tick0.05
mc.Events.KeyDownUserInputService.InputBeganinput, gameProcessed
mc.Events.KeyUpUserInputService.InputEndedinput, gameProcessed
mc.Events.Connectedstate (the new connection state)
mc.Events.Disconnectedstate (the connection state before disconnecting)
mc.Events.ServerChangednewServer, oldServer

The connection state is the table returned by mc.getConnectionState().

Notes:

  • The first reading after the script starts only sets a baseline. It never fires an event.
  • If the game cannot report its state for a moment (available is false), nothing fires.
  • ServerChanged fires when the server address changes, including when it changes to or from nil.
mc.Events.Connected:Connect(function(state)
  print("joined", state.server and state.server.address)
end)