Roblox Studio • Coding • Beginner
Roblox Studio Coding for Beginners: Write Your First Script
Make a part react when a player touches it while learning three ideas that show up throughout Roblox coding: object references, functions, and events.
What you will build
You’ll create a part in Roblox Studio that changes color when something touches it. The project is small on purpose: it gives a beginner a visible result while introducing the same coding structure used in larger games.
Before you start
- Open Roblox Studio on a Mac or Windows computer.
- Create or open a simple Baseplate project.
- Add one Part and make sure it is anchored.
Step 1: Add a Script
Select the Part in Explorer, click the plus icon, and add a Script. The script should be inside the Part so script.Parent refers to the object you want to control.
Step 2: Add the code
local part = script.Parent
local function changeColor()
part.Color = Color3.fromRGB(0, 170, 255)
end
part.Touched:Connect(changeColor)
Step 3: Test it
- Click Play.
- Move your character into the Part.
- Watch the Part change color.
- Stop the test, change the RGB numbers, and test again.
What the code means
Object reference
local part = script.Parent gives the script a short name for the Part it controls.
Function
changeColor stores the instructions we want Roblox to run.
Event
Touched tells Roblox when to run the function: when something touches the Part.
Try a creative challenge
Once the first version works, make one change of your own. Try a different color, change the Part’s transparency, or create two reactive Parts with different effects. Test after each change and explain what your code is doing.
Why this matters
Roblox games are built from the same pattern you just practiced: identify the object, decide what should happen, write instructions, connect them to an event, test the result, and improve it. Learning that pattern makes it much easier to build more complex game systems later.
Want personalized help with Roblox Studio?
Create2Discover 1-on-1 tutoring helps students build games while learning the coding logic behind them, with pacing, explanations, review, and project support matched to the learner.
Start with Roblox Studio building basics
Browse more Create2Discover resources
