Scheduler
Events
RunService, UserInputService and mc.Events.
RunService
Frame events. All of them are signals.
| Event | Fires | Arguments |
|---|---|---|
RunService.Stepped | Every frame, first | time, dt |
RunService.Tick | 20 times per second (fixed) | 0.05 |
RunService.Heartbeat | Every frame | dt |
RunService.RenderStepped | Every frame, last | dt |
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:
| Field | Meaning |
|---|---|
KeyCode | The key name as a string. Mouse buttons are "MouseLeft", "MouseRight", "MouseMiddle" |
UserInputType | The 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.
| Event | Same as | Arguments |
|---|---|---|
mc.Events.Render | RunService.RenderStepped | dt |
mc.Events.Heartbeat | RunService.Heartbeat | dt |
mc.Events.Tick | RunService.Tick | 0.05 |
mc.Events.KeyDown | UserInputService.InputBegan | input, gameProcessed |
mc.Events.KeyUp | UserInputService.InputEnded | input, gameProcessed |
mc.Events.Connected | state (the new connection state) | |
mc.Events.Disconnected | state (the connection state before disconnecting) | |
mc.Events.ServerChanged | newServer, 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 (
availableisfalse), nothing fires. ServerChangedfires when the server address changes, including when it changes to or fromnil.
mc.Events.Connected:Connect(function(state)
print("joined", state.server and state.server.address)
end)