Table of Contents
Why Events Matter in Roblox Scripts
In Roblox games, many interesting things happen as a result of something else. A player touches a brick, clicks a button, or walks into a door. Events are the way Roblox tells your scripts, “Something just happened. Do you want to react to it?”
In this chapter you will focus on two of the most common built-in events that are very important for beginners: Touched and MouseClick. You will see how they behave, what kind of information they give your code, and the usual mistakes to avoid when working with them.
You will connect functions to these events in the next chapter, so here you only learn what the events are and how they behave.
Events are signals, not loops. They only run your code when something happens, not all the time.
The Touched Event
The Touched event belongs to physical objects in the world. In Roblox terms these are usually BasePart objects, for example Part, WedgePart, or MeshPart. When another physical object touches that part, Roblox fires the Touched event.
This event is perfect for things that react when a player or any moving object comes into contact with them. For example, kill bricks in an obby, checkpoints, pressure plates, or doors that open when you step on a pad.
Conceptually, you can imagine Touched like this:
- Roblox runs its physics and moves everything.
- If Part A and Part B touch each other, Roblox fires the
Touchedevent on both. - Any script that is listening to that event will be notified.
The event also passes information about what touched the part. When Touched fires, it gives your handler a reference to the other part that made contact. You will later use that to figure out if it was a player, a projectile, or something else.
What Touched Actually Detects
Touched is a physics event. It does not care if the part belongs to a player or to a random object. If two parts collide, the event fires.
If a player walks into a brick, the event fires on the brick for every physics step where the contact is detected. That means your handler code can run many times while the player keeps touching the brick, not just once. When you want a “one time” effect, you will need to add your own logic to prevent the same action from repeating every physics step.
You can think of time in frames. If a player stands on a pad for 1 second and the game runs at 60 frames per second, then Touched can fire many times during that second. It is not a single “on touch start” event. It is more like “contact happened during this frame” repeated often.
Important rule for Touched:
Touched can fire many times while two parts stay in contact. If you want a one time effect, your code must ignore repeated touches.
Although Touched cares about parts, in practice you often want to know if the part belongs to a player. When a player touches a brick, the part that actually hits it is usually one of the character’s body parts, such as LeftFoot or RightHand. To turn that into a player, you will later navigate from the part to the character model, and then from the character to the Player object. That logic is part of connecting functions and player systems, which you will see in other chapters, but it is important to know that Touched itself only knows about parts.
When Touched Will Not Fire
Touched needs a physical collision. If Roblox’s physics system does not see an overlap between two parts, the event does not happen.
If both parts are CanCollide = false, they can pass through each other without a physical collision. In that case Touched will not fire unless some other setting or constraint still makes the engine think there is a touch.
When the workspace is paused or physics is not running, the event does not fire either. In normal gameplay you rarely need to think about this, but it explains why Touched is different from a manual check like a loop that constantly checks distances.
In addition, purely visual things, such as SurfaceGui or BillboardGui, never fire this event, because they are not physical parts. Only things that inherit from BasePart can raise Touched.
The Clicked Event and Click Detectors
The other beginner friendly event you will use often is the click event from ClickDetector. The event itself is usually accessed as MouseClick or RightMouseClick, but you first have to put a ClickDetector object inside a part.
A ClickDetector is not visible in the game by itself. It sits inside a part and tells Roblox, “If the player’s mouse clicks this part, fire an event.” This gives you an easy way to let players interact with objects from a distance, not by walking into them, but by clicking them.
When the player’s mouse cursor is over the part and the player clicks the left mouse button, the MouseClick event of the ClickDetector fires. When the player uses the right mouse button, RightMouseClick fires instead. These events are common for buttons, shops, doors that open when you click them, and any object that needs a simple mouse interaction.
Unlike Touched, the click events also tell you which player clicked. The event passes a reference to the Player that performed the click. Internally the engine looks at which player’s camera and mouse were used and passes that to your handler. That means MouseClick does more than just signal “something happened”. It also identifies who did it.
How Click Events Behave
The click events are user input events, not physics events. They depend on the player’s mouse cursor and their camera.
In order for the click to register, several things must be true at the moment of the click.
The cursor must be pointing at the part or at least at a surface that belongs to the part the ClickDetector is inside.
The player must not be in an interface mode that stops the 3D world from receiving clicks. For example, clicking on a GUI button does not trigger the 3D MouseClick event.
The part must be within the ClickDetector's MaxActivationDistance property. If the part is too far away, the click will not be accepted and the event will not fire.
If all of these conditions are met, MouseClick will fire exactly once for each mouse click. This is unlike Touched, which can fire many times while contact continues.
Important rule for click events:
For MouseClick to fire, the player must click while the cursor is over the part and within activation distance. The event fires once per click, not continuously.
The Difference Between Touched and Clicked
Both Touched and click events are ways to respond to player actions or world events, but they are used for different styles of interaction.
Touched is automatic and physical. The player only needs to move into the object or let something collide with it. You do not get a direct reference to the player, only to the part that touched your object.
Click events through ClickDetector are deliberate and visual. The player has to aim and click. You do not need a physical collision, and you get the player that clicked as part of the event. This makes them ideal for things like shops or doors that should not trigger just because someone walks too close.
In terms of control flow, both are event based. Your code does not need to loop and constantly check positions or input keys. Instead, it sleeps until Roblox fires the event, then runs your event handler once for that occurrence.
You will later connect these events to functions, control what happens, and combine them with other systems like health, coins, or UI. For now it is enough to clearly understand what each event represents, what triggers it, and what information it gives to your scripts.