Let’s make a brick respond to a character. You will connect an event, read an object, and add a cooldown so the same touch does not trigger dozens of changes.
Build your test brick
- Start with a new Baseplate place.
- Insert a Part into Workspace and name it ColorBrick.
- Set Anchored and CanTouch to true. Move it above the Baseplate where a player can reach it.
- Add a regular Script inside ColorBrick.
Connect the event
Replace the Script’s contents with the example below. Because the Script is inside the Part, script.Parent refers to that Part.
local brick = script.Parentlocal ready = truebrick.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid") if not humanoid or not ready then return end ready = false brick.Color = Color3.fromRGB( math.random(0, 255), math.random(0, 255), math.random(0, 255) ) task.wait(1) ready = trueend)Understand the code
Touched sends the touching part into our function as hit. The Humanoid check filters out most loose objects. A Humanoid can also belong to an NPC, so this is a character check, not proof of a player.
ready is a shared cooldown for this brick. The early return stops the function when a change is already in progress. After choosing a color, the script waits one second before allowing another change.
Test and troubleshoot
- Press Play and walk into the brick. Step away, wait a second, and touch it again.
- If nothing happens, confirm the Script is inside ColorBrick and is enabled.
- Check Output for an error and double-check spelling and capitalization.
- Test with two players to see that the server changes the color for everyone.
Make it your own
Change the wait to two seconds, then test again. Next, replace the random color with one fixed Color3.fromRGB value. Make one change at a time so you know which edit caused the result.
Ready for another mechanic? Try a teleport pad or review the Luau building blocks.
Build your next small idea.
Try the generator