Beginner
Getting Started with Roblox Studio
A complete introduction to Roblox Studio. Learn the interface, create your first part, and understand the basics of game structure before writing a single line of code.
getting-started-roblox-studio.lua
-- ============================================================
-- PLACE IN: ServerScript inside ServerScriptService
-- REQUIRES: Nothing! This script is completely self-contained.
-- ============================================================
-- ============================================================
-- š WELCOME TO CODING IN ROBLOX!
-- ============================================================
-- A SCRIPT is a set of instructions you give to your game.
-- Think of it like a recipe - the computer reads each line
-- one at a time, from top to bottom, and follows the steps.
--
-- TO SEE OUTPUT (the messages your script prints):
-- 1. Open Roblox Studio
-- 2. Click "View" in the top menu bar
-- 3. Click "Output" to open the Output window
-- 4. Press the Play button - messages will appear there!
--
-- TO USE THIS SCRIPT:
-- 1. Open the Explorer panel (View ā Explorer)
-- 2. Find "ServerScriptService" in the list
-- 3. Click the + button next to it
-- 4. Choose "Script"
-- 5. Delete everything inside and paste this code in!
-- ============================================================
-- ============================================================
-- SECTION 1: PRINTING MESSAGES
-- ============================================================
-- "print()" is the most basic tool in coding.
-- Anything you put inside the brackets will appear in Output.
-- The text must be wrapped in quotation marks " ".
print("Hello! Welcome to Roblox coding!") -- This prints a greeting
print("You just ran your first script!") -- This prints another message
print("Roblox uses a coding language called Luau.") -- Explaining the language
-- You can also do math inside print! No quotation marks needed for numbers.
print("2 + 2 =", 2 + 2) -- This will print: 2 + 2 = 4
-- A blank print() just prints an empty line - useful for spacing
print("")
print("=== Script is starting up! ===") -- A separator to keep things tidy
-- ============================================================
-- SECTION 2: VARIABLES - STORING INFORMATION
-- ============================================================
-- A VARIABLE is like a labeled box where you store information.
-- You create one by writing: local boxName = value
-- "local" means this variable belongs only to this script.
local gameName = "My First Roblox Game" -- Storing the game name as text
local magicNumber = 42 -- Storing a number
local isAwesome = true -- Storing true/false (called a "boolean")
-- Now we can use those variables inside print!
print("Welcome to:", gameName) -- Uses the gameName variable we made
print("The magic number is:", magicNumber) -- Uses the magicNumber variable
print("Is coding awesome?", isAwesome) -- Uses the isAwesome variable
print("") -- Blank line for spacing in the Output window
-- ============================================================
-- SECTION 3: GETTING ROBLOX SERVICES
-- ============================================================
-- Roblox is organized into "Services" - think of them like
-- departments in a company. Each department handles a specific job.
-- We use game:GetService("ServiceName") to access them.
-- "Players" service keeps track of everyone in the game
local Players = game:GetService("Players")
-- "Workspace" is where everything in the 3D world lives
local Workspace = game:GetService("Workspace")
-- "TweenService" lets us animate and smoothly change things
local TweenService = game:GetService("TweenService")
print("Services loaded! Roblox is ready to go.") -- Confirm services are ready
-- ============================================================
-- SECTION 4: CREATING A PART IN THE WORLD
-- ============================================================
-- A PART is one of the basic building blocks in Roblox.
-- We can create one with code instead of using the toolbar!
-- Instance.new("ClassName") creates a new object of that type.
-- Create a brand new Part object (it's invisible until we set Parent)
local magicPart = Instance.new("Part")
-- Give the part a name so we can find it in the Explorer later
magicPart.Name = "MagicGlowPart" -- The name shown in the Explorer panel
-- Set the SIZE of the part (X = width, Y = height, Z = depth)
magicPart.Size = Vector3.new(6, 6, 6) -- Makes a 6x6x6 cube
-- Set the POSITION of the part in the 3D world
-- Vector3 means a point in 3D space (X = left/right, Y = up/down, Z = forward/back)
magicPart.Position = Vector3.new(0, 5, 0) -- Places it at center, 5 studs up
-- Set the COLOR of the part using Color3.fromRGB (Red, Green, Blue - each 0 to 255)
magicPart.Color = Color3.fromRGB(255, 100, 200) -- A bright pink/purple color
-- Make the part a little see-through! 0 = fully visible, 1 = fully invisible
magicPart.Transparency = 0.2 -- Slightly transparent (20%)
-- "Anchored" means the part won't fall due to gravity
magicPart.Anchored = true -- Keep it floating in the air
-- Make the part SMOOTH and shiny (no texture bumps)
magicPart.Material = Enum.Material.Neon -- Neon makes it glow!
-- PARENT sets where the part lives in the Explorer hierarchy.
-- We always set Parent LAST - it's a Roblox performance best practice!
magicPart.Parent = Workspace -- Put the part into the 3D world
print("⨠Magic part created in the world!") -- Confirm the part was made
-- ============================================================
-- SECTION 5: ADDING A GLOW EFFECT (PointLight)
-- ============================================================
-- We can add special effects inside a Part.
-- A "PointLight" makes the part emit glowing light around it,
-- like a lightbulb! We parent it inside the part.
local glow = Instance.new("PointLight") -- Create the light effect
glow.Brightness = 5 -- How bright the light is (higher = brighter)
glow.Range = 20 -- How far the light reaches (in studs)
glow.Color = Color3.fromRGB(255, 100, 200) -- Match the part's pink color
glow.Parent = magicPart -- Put the light INSIDE the part so it glows from there
print("š” Glow effect added to the part!") -- Confirm the glow was added
-- ============================================================
-- SECTION 6: MAKING THE PART SPIN (Animation with Heartbeat)
-- ============================================================
-- "RunService.Heartbeat" fires every single frame of the game
-- (about 60 times per second). We can use it to animate things!
-- The "deltaTime" tells us how much time passed since last frame.
local RunService = game:GetService("RunService") -- Get the RunService department
local totalTime = 0 -- This variable will count how many seconds have passed
-- Connect a FUNCTION to Heartbeat. A FUNCTION is a block of code
-- that runs whenever the event fires. Think of it like a phone -
-- every time Heartbeat "rings", our function "picks up".
RunService.Heartbeat:Connect(function(deltaTime)
-- "deltaTime" is the tiny slice of time since the last frame
totalTime = totalTime + deltaTime -- Add this frame's time to our total
-- CFrame handles position AND rotation in Roblox
-- We rotate the part a tiny bit every frame based on time
-- math.sin() and math.cos() create smooth wave-like movement
magicPart.CFrame = CFrame.new(0, 5 + math.sin(totalTime * 2), 0) -- Bob up and down
* CFrame.Angles(0, totalTime * 2, 0) -- Spin on the Y axis (left/right)
end)
print("š Part is now spinning and bobbing!") -- Confirm the animation started
-- ============================================================
-- SECTION 7: REACTING WHEN A PLAYER TOUCHES THE PART
-- ============================================================
-- Parts have a built-in event called "Touched" that fires
-- whenever something makes contact with that part.
-- We can connect a function to it, just like we did with Heartbeat!
-- First, let's make a "debounce" to prevent the code from running
-- 100 times in one second when a player stands on the part.
-- A DEBOUNCE is like a cooldown - once something fires, we
-- wait a moment before letting it fire again.
local touchDebounce = false -- false means "ready to fire", true means "on cooldown"
-- Connect a function to the Touched event of our magic part
magicPart.Touched:Connect(function(otherPart)
-- "otherPart" is whatever just touched our magic part
-- It could be a player's foot, arm, or even another part!
-- Check if we're currently on cooldown - if so, stop here
if touchDebounce then
return -- "return" exits the function early, doing nothing
end
-- Try to find the player who owns this body part that touched us
-- Every player character has body parts (like "LeftFoot", "Head", etc.)
-- GetPlayerFromCharacter() traces back from body part ā character ā player
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
-- Check if we actually found a real player (not just a random part)
if player then
-- We found a real player! Set debounce to true (start cooldown)
touchDebounce = true
-- Print a personal welcome message using the player's name
-- The ".." symbol JOINS text together (called "concatenation")
print("ā " .. player.Name .. " touched the Magic Part!") -- Greet by name
print(" ā Changing the part color for a moment...") -- Tell what's happening
-- Change the part's color to yellow as a reaction
magicPart.Color = Color3.fromRGB(255, 220, 0) -- Bright yellow color
-- Also update the glow color to match
glow.Color = Color3.fromRGB(255, 220, 0) -- Yellow glow to match
-- task.wait() pauses the script for a number of seconds.
-- This is like saying "do nothing for 1 second"
-- We use task.wait() - NEVER use the old wait() function!
task.wait(1) -- Wait 1 second before changing back
-- Change the color back to the original pink/purple
magicPart.Color = Color3.fromRGB(255, 100, 200) -- Back to pink
glow.Color = Color3.fromRGB(255, 100, 200) -- Glow back to pink too
print(" ā Color restored! Ready for the next player.") -- Confirm reset
-- Reset the debounce after a short cooldown period
task.wait(1) -- Wait 1 more second before allowing touches again
touchDebounce = false -- Set back to false so it can fire again
end
end)
print("š Touch detection is now active on the magic part!") -- Confirm touch is set up
-- ============================================================
-- SECTION 8: DOING SOMETHING WHEN A PLAYER JOINS
-- ============================================================
-- Players.PlayerAdded fires every time a new player joins the game.
-- This is great for greeting new arrivals!
Players.PlayerAdded:Connect(function(player)
-- "player" is the Player object for whoever just joined
-- Print a welcome message with their name
print("š® " .. player.Name .. " just joined the game! Welcome!") -- Greet them
-- Wait 1 second before giving them instructions
task.wait(1) -- Small pause so messages appear in order
print(" ā " .. player.Name .. ", go touch the glowing cube!") -- Guide them
end)
print("š Player join detection is active!") -- Confirm the event is connected
-- ============================================================
-- SECTION 9: DOING SOMETHING WHEN A PLAYER LEAVES
-- ============================================================
-- PlayerRemoving fires when a player leaves or disconnects.
Players.PlayerRemoving:Connect(function(player)
-- "player" is whoever just left the game
print("š " .. player.Name .. " has left the game. Goodbye!") -- Say farewell
end)
print("šŖ Player leave detection is active!") -- Confirm this event is ready
-- ============================================================
-- SECTION 10: FINAL STARTUP MESSAGE
-- ============================================================
-- This is the last thing that runs when the script first loads.
-- By this point, everything above is set up and ready to go!
print("") -- Blank line for visual spacing
print("============================================") -- Decorative border
print(" ā
SCRIPT FULLY LOADED AND RUNNING!") -- Big success message
print(" š£ Look for the glowing pink cube!") -- Tell them what to look for
print(" š Walk into it to see the touch event!") -- Explain what to do
print(" šŗ All events will appear here in Output!") -- Remind where to look
print("============================================") -- Decorative border
print("") -- Final blank line
-- ============================================================
-- š WHAT DID WE LEARN?
-- ============================================================
-- ā
print() ā Shows messages in the Output window
-- ā
Variables ā Named boxes that store information
-- ā
Services ā Roblox departments we access with GetService
-- ā
Instance.new() ā Creates new objects like Parts and Lights
-- ā
Functions ā Blocks of code that run when called
-- ā
Events ā Things that happen (touch, join, heartbeat)
-- ā
Connect() ā Links a function to an event
-- ā
task.wait() ā Pauses the script for X seconds
-- ā
Debounce ā A cooldown that prevents rapid event firing
-- ā
if/then ā Only run code when a condition is true
-- ============================================================
š **Setup:**
- **Where to place it:** Open the **Explorer** panel (View ā Explorer), find **ServerScriptService**, click the ā next to it, choose **Script**, delete the default `print("Hello world!")` line, and paste this entire script in.
- **How to see the output:** Go to **View ā Output** to open the Output window at the bottom of Studio. Press the ā¶ļø **Play** button and all the messages will appear there in real time.
- **What you'll see in the world:** A glowing **pink cube** will appear at the center of the map, floating and spinning slowly. Walk your character into it and it will flash yellow!
- **No extra setup needed:** This script creates everything itself ā the part, the light, and all the event listeners. Nothing to build in advance.
- **Great next steps:** Try changing the numbers in `Color3.fromRGB(...)`, `magicPart.Size`, or the `glow.Brightness` and press Play again to see what happens ā experimenting is the best way to learn! š
Want this written for your specific game?
Describe exactly what you need and get working Luau code in seconds.
Try the AI Generator ā