Learn How to Code Games in Roblox Studio¶
Udemy Course¶
https://www.udemy.com/course/code-a-simple-game-in-roblox-studio/
https://nlbsg.udemy.com/course/code-a-simple-game-in-roblox-studio/
Roblox¶
Using Studio
Building with Parts
Building with Physics
Building Terrain
Lighting Environment
Atmosphere Environment
Effects Environment
Importing Assets
GameStructure and Collaboration
Lua Overview
Collisions, Humanoids,Score
Interacting with GUIs
Coding Animation
Sounds and Music
Using the AnimationEditor
Combat,Teleporting,DataStores
Multiplayer Code and the Client-ServerModel
Module Scripts
Coding Camera Movements
Cross Platform Building
Global Community Building
Code¶
Program to Print the String¶
--- print("Hello Senthil")
--
local myString = "Hi my name is Senthil"
print(typeof(myString))
print(myString)
-- This is a number variable
local myInteger = 32.67
print(typeof(myInteger))
print(myInteger)
local myBoolean = true
print(typeof(myBoolean))
print(myBoolean)
Program with Conditional Statement¶
local myString = "Hi my name is Senthil"
local myInteger = 32.67
local myBoolean = true
print(myString)
myString = "My name is now Darth Vader"
print(myString)
if myBoolean == true then
print("My boolean is true")
else
print("My boolean is false")
end
if myInteger > 30 then
print("My integer is greater than 30")
else
print("My integer is less than 30")
end
if (1 + 1 == 3) then
print("1 + 1 is 3")
else
print("1 + 1 is not 3. It is 2")
end
Program with Conditional Statements and Boolean¶
local age = 15
local movieRating = "M"
if age >= 15 then
print("You can watch the M rated movie")
else
print("You are too young to watch the M rated movie")
end
movieRating = "G"
if movieRating == "G" then
print("You can watch the G rated movie")
end
movieRating = "M"
if age >= 15 and movieRating == "M" then
print("You can watch the M rated movie")
end
Functions¶
local myName = "Senthil"
-- The dot dot symbol is called concatenation operator
local function sayMyName()
print("My name is " .. myName)
end
sayMyName()
myName = "Kumaran"
sayMyName()
Functions with Parameters¶
local function sayMyName(myName, age)
print("Hello, " .. myName)
print("I am " .. age .. " years old")
end
sayMyName("Senthil", 42)
Parameter Strings¶
local function addNums(num1, num2)
return num1 + num2
end
local answer = addNums(1, 2)
print(answer)
Calculator with String¶
local function addNums(n1, n2)
return n1 .. " + " .. n2 .. " = " .. (n1 + n2)
end
local answer = addNums(1, 2)
print(answer)
Part¶
local myPart = script.Parent
myPart.BrickColor = BrickColor.new("Bright red")
myPart.BrickColor = BrickColor.Random()
Workspace¶
local myPart = game.Workspace.Part
myPart.Transparency = 0.5
local myBridge = game.Workspace.Bridge
myBridge.Grass.BrickColor = BrickColor.Random()
When creating a part, make it anchored.
Touching the part¶
local myPart = script.Parent
myPart.BrickColor = BrickColor.Random()
local function partTouchedFunction(partTouched)
print(partTouched)
end
myPart.Touched:Connect(partTouchedFunction)
Changing Brick Color with Touch¶
local myPart = script.Parent
-- debounce
local db = true
local function partTouchedFunction(partTouched)
if db then
db = false
myPart.BrickColor = BrickColor.Random()
wait(2)
db = true
end
end
myPart.Touched:Connect(partTouchedFunction)
Inline Touch Function¶
local myPart = script.Parent
-- debounce
local db = true
myPart.Touched:Connect(function(partTouched)
if db then
db = false
myPart.BrickColor = BrickColor.Random()
wait(2)
db = true
end
end)
Player touch the part¶
-- Player = This is you!
-- Humanoid - A little robot
-- Character - This is how you look in the game.
--
local myPart = script.Parent
-- debounce
local db = true
myPart.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid and db then
local player = game.Players:GetPlayerFromCharacter(character)
-- game.Players:FindFirstChild(character.Name)
db = false
myPart.BrickColor = BrickColor.Random()
print(player.Name .. " touched the part!")
wait(2)
db = true
end
end)
-- Test this. Player can change the color of the part by touching it.
-- Moving another block against it will not change the color.
Pick up the Part¶
-- Create a Spawn point.
-- Create a part to pick up. Rename it to "Pickup"
-- Anchored
-- Add a Script and rename it to pickupScript
--
--
local pickup = script.Parent
local db = true
pickup.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid and db then
local player = game.Players:GetPlayerFromCharacter(character)
-- game.Players:FindFirstChild(character.Name)
db = false
pickup.Transparency = 1
pickup.CanCollide = false
print(player.Name .. " picked up the part!")
wait(2)
pickup.Transparency = 0
pickup.CanCollide = true
db = true
end
end)
Sign to pick up the part¶
-- Create a Spawn point.
-- Create a part to pick up. Rename it to "Pickup"
-- Anchored
-- Add a Script and rename it to pickupScript
--
local sign = game.Workspace.signModel.backboard.SurfaceGui.Frame.TextLabel
local pickup = script.Parent
local db = true
pickup.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid and db then
local player = game.Players:GetPlayerFromCharacter(character)
-- game.Players:FindFirstChild(character.Name)
db = false
pickup.Transparency = 1
pickup.CanCollide = false
sign.Text = "You have picked up the item!"
print(player.Name .. " picked up the part!")
wait(5)
pickup.Transparency = 0
pickup.CanCollide = true
sign.Text = "Pick up the part!"
db = true
end
end)
Camping Project¶
LeaderBoard¶
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
end)
end)
Log Pickup¶
-- logScript
local log = script.Parent
local db = true
log.Touched:Connect(function(hit)
local character = hit.Parent
local hum = char:FindFirstChild("Humanoid")
if db and hum then
db = false
local plr = game.Players:FindFirstChild(char.Name)
local pStats = plr:WaitForChild("leaderstats")
log.Transparency = 1
wait(3)
log.Transparency = 0
db = true
end
end)
Roblox Programming - 2023¶
Pass The Ice Wall¶
-- Add this 1
local wall = workspace.iceWall
local myName = "Bill"
local myAge = 12
local isAllowedToGoCamping = true
-- Add this 3
task.wait(5)
-- Add this 2
if myName == "Bill" then
print("Yes your name is ", myName)
wall.Transparency = 0.3
else
warn("No your name is not Bill")
end
task.wait(5)
if myAge >= 10 then
print("Yes you are ", myAge, " you are old enough to go camping")
wall.Transparency = 0.6
end
if isAllowedToGoCamping == true then
print("Yes you are allowed to go camping")
wall.Transparency = 1
wall.CanCollide = false
end