Answered Plainly
Display: Text size:

Making Things Happen: Events in Roblox

The short answer: Roblox games are event-driven. Things happen — a player joins, a foot lands on a part — and those happenings are called events. Your job is to connect a function to an event with :Connect(), so your code runs when the event fires. This page connects a step-plate, builds a color-cycling disco floor from Roblox's own tutorial pattern, and covers the one problem every touch script meets: it fires too many times — and how a cooldown (also called a debounce) fixes it.

Events: the game taps you on the shoulder

Events fire whether you listen or not. A player's character touching a part automatically fires that part's Touched event. Every player who joins fires the PlayerAdded event. When you want to respond, you connect a function, and the event hands that function some information: Touched passes the object that touched the part (a foot, a wheel, a falling block), and PlayerAdded passes the player who joined.

Here is the smallest useful event script. Put it inside a part — a Script whose parent is the part, so script.Parent means the part:

-- Put this Script inside the part you want to watch.
local part = script.Parent

local function onPartTouched(otherPart)
	print("Something touched this part:", otherPart.Name)
end

part.Touched:Connect(onPartTouched)

What you should see: run the game, walk your character onto the part, and Output fills with messages like Something touched this part: LeftFoot — once for every body part and every object that bumps into it. Notice how many messages one step makes. Remember that; it matters below.

Three more facts about connections, from the events guide:

A disco floor: color on a loop

This one comes straight from the pattern in Roblox's own points tutorial: store colors in variables, then loop forever, changing the part's color and waiting between changes. The while true loop sits at the bottom of the script — anything placed under a never-ending loop never runs — and every round pauses with task.wait(), which is what keeps an endless loop from freezing Studio (page 4's warning).

-- Put this Script inside the part. The part loops through three colors forever.
local part = script.Parent

local blue = Color3.fromRGB(0, 0, 255)
local green = Color3.fromRGB(0, 255, 0)
local red = Color3.fromRGB(255, 0, 0)

while true do
	part.Color = blue
	task.wait(3)
	part.Color = green
	task.wait(3)
	part.Color = red
	task.wait(3)
end

What you should see: the part turns blue, then green, then red, three seconds each, forever. Color3.fromRGB builds a color out of three numbers from 0 to 255 — how much red, green, and blue light to mix. Try your own mixes; (255, 200, 0) makes a gold.

The touch problem — and the cooldown fix

Look back at the first example's Output: one step fired Touched many times. A foot, a leg, the other foot, the torso — every contact fires it, and it keeps firing while a player stands on the part. That is fine for printing messages, but it is a disaster for prizes: a points plate would pay out dozens of times for one step. Roblox's own points tutorial solves it by destroying the part after it pays out once. The gentler, more reusable fix is a cooldown — scripters also call it a debounce: after the plate counts a player, it ignores that player for a few seconds.

This script finds who touched the plate and gives each player their own 2-second rest. Finding the player works like this: the thing that touched the part is a body part, its Parent is the player's character (the body model you see in the game), and Players:GetPlayerFromCharacter() turns that character into the player. If a random block rolls onto the plate, there is no player, and the script quietly does nothing.

-- Put this Script inside the part. Each player can trigger it once every 2 seconds.
local part = script.Parent
local Players = game:GetService("Players")

local cooldowns = {}
local COOLDOWN_TIME = 2

local function onPartTouched(otherPart)
	local player = Players:GetPlayerFromCharacter(otherPart.Parent)
	if not player then
		return
	end

	local lastTouch = cooldowns[player] or 0
	if tick() - lastTouch < COOLDOWN_TIME then
		return
	end
	cooldowns[player] = tick()

	print(player.Name .. " stepped on the plate!")
end

part.Touched:Connect(onPartTouched)

How the cooldown works: the cooldowns table (page 4) keeps one entry per player: the last time the plate counted them. tick() is a clock that counts seconds. If this player's last counted touch was less than COOLDOWN_TIME seconds ago, the function returns early and ignores the touch. Otherwise it stamps the new time and does its work. This exact shape — a cooldown table, a clock, an early return — is the pattern Roblox's own security guide uses to slow down actions that players can trigger, because anything a player can trigger can also be spammed.

Meet the character, briefly: from the player you can reach the body with player.Character. Scripts often look inside the character with WaitForChild or FindFirstChild — Roblox's own examples find the character's Head, and find HumanoidRootPart, the part at the character's center, when they need to know where the character is standing. You will use the character constantly from here on.

Sources (official only; read in full November 7, 2026):

The Roblox code on this page cannot run outside Studio, so each script was checked line by line against the documentation above — and its logic was also run on this machine against a small fake Roblox setup, where the touch, print, and cooldown behavior matched what this page describes. Checked November 7, 2026.