Working With Roblox Events
Games are event-driven: a player joins, a part is touched, a button is clicked. Roblox exposes these moments as events, and connecting functions to them is how your scripts react to what is happening. This is the heart of almost every gameplay script.
Get a free executor
You need an executor to run any Roblox script. Grab one free.
What is an event?
An event is a signal the game fires when something happens. You listen for it with :Connect(), passing the function to run: part.Touched:Connect(onTouch). When the part is touched, your function runs — automatically, every time.
This flips your mental model from "do these steps once" to "set up reactions, then let the game drive them".
Common events
A few you will use constantly:
- Players.PlayerAdded — runs when someone joins.
- part.Touched — runs when something touches a part.
- button.MouseButton1Click — runs when a UI button is clicked.
- RunService.Heartbeat — runs every frame, for continuous logic.
Connections and cleanup
Connect returns a connection object. If you connect something temporary, keep that object and call :Disconnect() when you are done — leftover connections are a classic source of lag and memory leaks.
Cleaning up connections you no longer need is one of the simplest ways to keep a long-running script healthy.
Where to go next
Event handlers usually call creating custom functions you have written, and update the screen via creating user interfaces. When an event misbehaves, debugging your scripts helps you trace it.