Our Roblox and Lua (Level 2) class focuses on advancing scripting skills in Roblox using Lua. Students will learn advanced topics such as creating interactive elements, saving game data, event handling, GUI integration, user tools, team-based mechanics, and creating complex game systems. Projects include building interactive games, designing user interfaces, implementing in-game purchases, and creating team-based mechanics, culminating in a final project where students showcase their own game creations.
Students will learn intermediate/advanced game designing and development on Roblox Studio using Lua code
Week 1
Lesson 1
Intro to CFRAME
Create a function that moves the part up and down(CFRAME) Make 2 bricks that call these 3 functions, and create a light show
PROJECT 1: Create a light show
We created a general layout for our world, and discussed some game post-processing effects. We then created animation effects using the TweenService.
Code from today in TestScript in ServerScriptService: local TweenService = game:GetService("TweenService") local Part = Instance.new("Part", workspace) Part.Anchored = true Part.Size = Vector3.new(15,15,15) Part.CFrame = CFrame.new(0,30,0) wait(2) local Info = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 5, true, 0.5) local Prop = { Transparency = 1, \["CFrame"\] = CFrame.new(0,0,0), Color = Color3.fromRGB(255,0,0), } local Animation = TweenService:Create(Part, Info, Prop) Animation:Play()
Code from today in TestScript in ServerScriptService:
local TweenService = game:GetService("TweenService")
local Part = Instance.new("Part", workspace)
Part.Anchored = true
Part.Size = Vector3.new(15,15,15)
Part.CFrame = CFrame.new(0,30,0)
wait(2)
local Info = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 5, true, 0.5)
local Prop = {
Transparency = 1,
["CFrame"] = CFrame.new(0,0,0),
Color = Color3.fromRGB(255,0,0),
}
local Animation = TweenService:Create(Part, Info, Prop)
Animation:Play()
Week 2
Lesson 2
How to save data in your game
Creating a leaderboard using Functions Explain what the functions we have used are, more into them. Event handling (Basics) Explain the idea of saving data in our game. Create a leaderboard that shows the player's name and the amount of Script that saves the player's gold to DataStorage.
PROJECT 2: Create an on-hit brick that will increase the amount of gold the player has.
Today we created our data store within our game to save coins. We then began to create our generating of coins throughout the world physically.
Code from today in GameScript:
local DataStoreService = game:GetService("DataStoreService") local Players = game:GetService("Players") local MainDataStore = DataStoreService:GetDataStore("MainDataStore") local function GenerateCoins(amount) local PartA = workspace:WaitForChild("PartA") local PartB = workspace:WaitForChild("PartB") local region = Region3.new(PartA.Position, PartB.Position) local function RandomPosition(region) local min = region.CFrame.Position - region.Size / 2 local max = region.CFrame.Position + region.Size / 2 local randomX = math.random() \* (max.X - min.X) + min.X local randomY = math.random() \* (max.Y - min.Y) + min.Y local randomZ = math.random() \* (max.Z - min.Z) + min.Z return Vector3.new(randomX, randomY, randomZ) end for i = 1,amount,1 do local coin = script:WaitForChild("Coin"):Clone() coin.Parent = workspace coin.Position = RandomPosition(region) end end GenerateCoins(100) Players.PlayerAdded:Connect(function(newPlayer) --Checks for new player joining local leaderstats = Instance.new("Folder", newPlayer) leaderstats.Name = "leaderstats" local gold = Instance.new("IntValue", leaderstats) gold.Name = "Gold" local success, errorMessage = pcall(function() --Protected function call local data = MainDataStore:GetAsync(newPlayer.UserId) return data end) if not success then print(errorMessage) return end local data = errorMessage gold.Value = data or 0 end) Players.PlayerRemoving:Connect(function(leavingPlayer) local leaderstats = leavingPlayer:WaitForChild("leaderstats") local gold = leaderstats:WaitForChild("Gold") local success, errorMessage = pcall(function() --Protected function call local data = MainDataStore:SetAsync(leavingPlayer.UserId, gold.Value) end) if success then print("Saved data for: " .. tostring(leavingPlayer.UserId)) else print(errorMessage) end end)
Code:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local MainDataStore = DataStoreService:GetDataStore("MainDataStore")
Players.PlayerAdded:Connect(function(newPlayer) --Checks for new player joining
local leaderstats = Instance.new("Folder", newPlayer)
leaderstats.Name = "leaderstats"
local gold = Instance.new("IntValue", leaderstats)
gold.Name = "Gold"
local success, errorMessage = pcall(function() --Protected function call
local data = MainDataStore:GetAsync(newPlayer.UserId)
return data
end)
if not success then print(errorMessage) return end
local data = errorMessage
gold.Value = data or 0
end)
Players.PlayerRemoving:Connect(function(leavingPlayer)
local leaderstats = leavingPlayer:WaitForChild("leaderstats")
local gold = leaderstats:WaitForChild("Gold")
local success, errorMessage = pcall(function() --Protected function call
local data = MainDataStore:SetAsync(leavingPlayer.UserId, gold.Value)
end)
if success then
print("Saved data for: " .. tostring(leavingPlayer.UserId))
else
print(errorMessage)
end
end)
Week 3
Lesson 3
Creating on-hit gold to collect
Beginning of our Gold Collection game. Use C-frame to make gold bricks move. Create a Diamond Brick, that is changing colors, and gives a ton of gold. Speed up the script that takes the gold from the player leaderboard.
PROJECT 3: Create a game that involves gathering the max amount of gold.
Today we finished up making our coin system in the game. We got coins that can spin, add to our gold amount, and can be touched. We will implement sound on them tomorrow and begin our base creations.
Updated code from today with comments:
-- Get references to essential Roblox services
local DataStoreService = game:GetService("DataStoreService") -- Service for saving and loading data
local Players = game:GetService("Players") -- Service to manage players
local TweenService = game:GetService("TweenService") -- Service for creating animations
-- Get a reference to a DataStore named "MainDataStore"
local MainDataStore = DataStoreService:GetDataStore("MainDataStore")
-- Function to generate coins in a specified region
local function GenerateCoins(amount)
local PartA = workspace:WaitForChild("PartA") -- First part defining the region
local PartB = workspace:WaitForChild("PartB") -- Second part defining the region
-- Define a region using PartA and PartB positions
local region = Region3.new(PartA.Position, PartB.Position)
-- Function to generate a random position within a region
local function RandomPosition(region)
local min = region.CFrame.Position - region.Size / 2 -- Minimum corner of the region
local max = region.CFrame.Position + region.Size / 2 -- Maximum corner of the region
-- Generate random coordinates within the defined region
local randomX = math.random() * (max.X - min.X) + min.X
local randomY = math.random() * (max.Y - min.Y) + min.Y
local randomZ = math.random() * (max.Z - min.Z) + min.Z
return Vector3.new(randomX, randomY, randomZ) -- Return the random position as a Vector3
end
-- Create a new folder to hold all the coin instances
local coinFolder = Instance.new("Folder", workspace)
coinFolder.Name = "Coins"
-- Table to store references to coin animations
local coinList = {}
-- Loop to create the specified amount of coins
for i = 1, amount, 1 do
-- Clone a coin model from a template in the script
local coin = script:WaitForChild("Coin"):Clone()
coin.Parent = coinFolder -- Parent the cloned coin to the coinFolder
coin.Position = RandomPosition(region) -- Set a random position for the coin
-- Connect a function to the coin's Touched event
coin.Touched:Connect(function(part)
-- Check if the touching part is a player character model
if part and part.Parent:IsA("Model") and Players:GetPlayerFromCharacter(part.Parent) then
local player = Players:GetPlayerFromCharacter(part.Parent) -- Get the player from the character
-- Check if the coin is visible (not collected yet)
if coin.Transparency == 0 then
coin.Transparency = 1 -- Make the coin invisible (collected)
player:FindFirstChild("leaderstats"):FindFirstChild("Gold").Value += 1 -- Increase player's gold by 1
wait(math.random(30,90)) -- Wait a random time before respawning the coin
coin.Transparency = 0 -- Make the coin visible again
end
end
end)
-- Create an animation for rotating the coin
local animInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1, false)
local prop = {["CFrame"] = (coin.CFrame * CFrame.Angles(0, math.rad(180), 0))} -- Rotate 180 degrees
local anim = TweenService:Create(coin, animInfo, prop) -- Create a tween for the coin
table.insert(coinList, anim) -- Add the animation to the list
end
-- Start a coroutine to play the animations continuously
spawn(function()
while true do
for i, v in pairs(coinList) do
v:Play() -- Play each coin animation
end
wait() -- Wait briefly before playing the next animation
end
end)
end
-- Call the function to generate 100 coins in the defined region
GenerateCoins(100)
-- Connect a function to handle new players joining the game
Players.PlayerAdded:Connect(function(newPlayer)
-- Create a folder to store player statistics
local leaderstats = Instance.new("Folder", newPlayer)
leaderstats.Name = "leaderstats"
-- Create a new IntValue to track player's gold
local gold = Instance.new("IntValue", leaderstats)
gold.Name = "Gold"
-- Attempt to load the player's saved data
local success, errorMessage = pcall(function()
local data = MainDataStore:GetAsync(newPlayer.UserId) -- Retrieve saved data using player's UserId
return data
end)
if not success then print(errorMessage) return end -- Print error if data retrieval fails
local data = errorMessage -- If successful, use the retrieved data
gold.Value = data or 0 -- Set the player's gold value to the retrieved data or 0 if no data
end)
-- Connect a function to handle players leaving the game
Players.PlayerRemoving:Connect(function(leavingPlayer)
local leaderstats = leavingPlayer:WaitForChild("leaderstats") -- Wait for leaderstats to exist
local gold = leaderstats:WaitForChild("Gold") -- Wait for gold value to exist
-- Attempt to save the player's data
local success, errorMessage = pcall(function()
MainDataStore:SetAsync(leavingPlayer.UserId, gold.Value) -- Save the player's gold value
end)
if success then
print("Saved data for: " .. tostring(leavingPlayer.UserId)) -- Confirm data saved
else
print(errorMessage) -- Print error if saving fails
end
end)
Week 4
Lesson 4
Displaying names above bricks in your game, and scripting purchases with in-game
How to use GUI in game Create 2 bricks that will act as on-hit bricks. Create functions in these bricks. Make it so when the player hits these bricks, it changes its humanoid attributes. Create a tile that buys walls or objects
PROJECT 4: Create 2 buttons, that change the players when they touch them
Today we finished up our coins and added sound effects to gathering them. We then created the bases and teams to go along with them.
Code:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local MainDataStore = DataStoreService:GetDataStore("MainDataStore")
local Bases = {}
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "Base" then
table.insert(Bases, v)
end
end
function GenerateCoins(amount)
local PartA = workspace:WaitForChild("PartA")
local PartB = workspace:WaitForChild("PartB")
local region = Region3.new(PartA.Position, PartB.Position)
local function RandomPosition(region)
local min = region.CFrame.Position - region.Size / 2
local max = region.CFrame.Position + region.Size / 2
local randomX = math.random() * (max.X - min.X) + min.X
local randomY = math.random() * (max.Y - min.Y) + min.Y
local randomZ = math.random() * (max.Z - min.Z) + min.Z
return Vector3.new(randomX, randomY, randomZ)
end
local coinFolder = Instance.new("Folder", workspace)
coinFolder.Name = "Coins"
local coinList = {}
for i = 1,amount,1 do
local coin = script:WaitForChild("Coin"):Clone()
coin.Parent = coinFolder
coin.Position = RandomPosition(region)
coin.Touched:Connect(function(part)
if part and part.Parent:IsA("Model") and Players:GetPlayerFromCharacter(part.Parent) then
local player = Players:GetPlayerFromCharacter(part.Parent)
if coin.Transparency == 0 then
coin.Transparency = 1
coin.CoinSound:Play()
player:FindFirstChild("leaderstats"):FindFirstChild("Doubloons").Value += 1
wait(math.random(30,90))
coin.Transparency = 0
end
end
end)
local animInfo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,1,false)
local prop = {Orientation = Vector3.new(180,0,0)}
local anim = TweenService:Create(coin, animInfo, prop)
table.insert(coinList, anim)
end
spawn(function()
while true do
wait(2)
for i,v in pairs(coinList) do
v:Play()
end
end
end)
end
GenerateCoins(100)
Players.PlayerAdded:Connect(function(newPlayer) --Checks for new player joining
local leaderstats = Instance.new("Folder", newPlayer)
leaderstats.Name = "leaderstats"
local gold = Instance.new("IntValue", leaderstats)
gold.Name = "Doubloons"
local charactor = newPlayer.CharacterAdded:Wait()
local randomNum = math.random(1,4)
for i,v in pairs(Bases) do
if i == randomNum then
charactor:MoveTo(v.SpawnLocation.Position)
newPlayer.TeamColor = v.SpawnLocation.TeamColor
end
end
local success, errorMessage = pcall(function() --Protected function call
local data = MainDataStore:GetAsync(newPlayer.UserId)
return data
end)
if not success then print(errorMessage) return end
local data = errorMessage
gold.Value = data or 0
end)
Players.PlayerRemoving:Connect(function(leavingPlayer)
local leaderstats = leavingPlayer:WaitForChild("leaderstats")
local gold = leaderstats:WaitForChild("Doubloons")
local success, errorMessage = pcall(function() --Protected function call
local data = MainDataStore:SetAsync(leavingPlayer.UserId, gold.Value)
end)
if success then
print("Saved data for: " .. tostring(leavingPlayer.UserId))
else
print(errorMessage)
end
end)
Week 5
Lesson 5
Intro to user tools, scripting tools.
Create a wand that changes the weather Create brick, so when the users touch it(if they have enough gold) they buy the items, and it shows up in their inventory.
PROJECT 5: Creating items that players can use.
Today we created an interface to select our own teams when a player joins. We also created a temporary waiting location while selecting a team.
The following code is an edited version of yesterday's code.
Code:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local MainDataStore = DataStoreService:GetDataStore("MainDataStore")
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
RemoteEvent.OnServerEvent:Connect(function(player, team)
player.Team = game:GetService("Teams"):FindFirstChild(team)
player:LoadCharacter()
end)
local Bases = {}
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "Base" then
table.insert(Bases, v)
end
end
function GenerateCoins(amount)
local PartA = workspace:WaitForChild("PartA")
local PartB = workspace:WaitForChild("PartB")
local region = Region3.new(PartA.Position, PartB.Position)
local function RandomPosition(region)
local min = region.CFrame.Position - region.Size / 2
local max = region.CFrame.Position + region.Size / 2
local randomX = math.random() * (max.X - min.X) + min.X
local randomY = math.random() * (max.Y - min.Y) + min.Y
local randomZ = math.random() * (max.Z - min.Z) + min.Z
return Vector3.new(randomX, randomY, randomZ)
end
local coinFolder = Instance.new("Folder", workspace)
coinFolder.Name = "Coins"
local coinList = {}
for i = 1,amount,1 do
local coin = script:WaitForChild("Coin"):Clone()
coin.Parent = coinFolder
coin.Position = RandomPosition(region)
coin.Touched:Connect(function(part)
if part and part.Parent:IsA("Model") and Players:GetPlayerFromCharacter(part.Parent) then
local player = Players:GetPlayerFromCharacter(part.Parent)
if coin.Transparency == 0 then
coin.Transparency = 1
coin.CoinSound:Play()
player:FindFirstChild("leaderstats"):FindFirstChild("Doubloons").Value += 1000000000
wait(math.random(30,90))
coin.Transparency = 0
end
end
end)
local animInfo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,1,false)
local prop = {Orientation = Vector3.new(180,0,0)}
local anim = TweenService:Create(coin, animInfo, prop)
table.insert(coinList, anim)
end
spawn(function()
while true do
wait(2)
for i,v in pairs(coinList) do
v:Play()
end
end
end)
end
GenerateCoins(100)
Players.PlayerAdded:Connect(function(newPlayer) --Checks for new player joining
local leaderstats = Instance.new("Folder", newPlayer)
leaderstats.Name = "leaderstats"
local gold = Instance.new("IntValue", leaderstats)
gold.Name = "Doubloons"
repeat wait() until newPlayer.Character
local charactor = newPlayer.Character
local randomNum = math.random(1,4)
for i,v in pairs(Bases) do
if i == randomNum then
charactor:MoveTo(v.SpawnLocation.Position)
newPlayer.TeamColor = v.SpawnLocation.TeamColor
end
end
newPlayer.Team = nil
charactor:MoveTo(workspace.TempLocation.Position)
local success, errorMessage = pcall(function() --Protected function call
local data = MainDataStore:GetAsync(newPlayer.UserId)
return data
end)
if not success then print(errorMessage) return end
local data = errorMessage
gold.Value = data or 0
end)
Players.PlayerRemoving:Connect(function(leavingPlayer)
local leaderstats = leavingPlayer:WaitForChild("leaderstats")
local gold = leaderstats:WaitForChild("Doubloons")
local success, errorMessage = pcall(function() --Protected function call
local data = MainDataStore:SetAsync(leavingPlayer.UserId, gold.Value)
end)
if success then
print("Saved data for: " .. tostring(leavingPlayer.UserId))
else
print(errorMessage)
end
end)
Addition to make the above code work:
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("TextButton")then
v.MouseButton1Click:Connect(function()
RemoteEvent:FireServer(v.Name)
script.Parent.Visible = false
end)
end
end
Week 6
Lesson 6
Animations
Create a block that allows the user to buy the sword Create sword Script sword when they buy the sword, the block disappears. Go over how to create animations
Week 7
Lesson 7
Spawns
Creating user bases Create spawns, so when the user touches them they join that team. Create bases, so you have to be on a certain team to purchase that team's swords/powerups. Create a door that checks if you are on the team, and if so, disables CanCollide, and becomes transparent.
Week 8
Lesson 8
Create Data Store
Combining this all to make a game Create teams for 4 bases Create a leaderboard that displays teams(1 per team), gold amount, and player Create Gold around the world, that is collectible(normal gold, Diamond Gold) Create a Data Store for gold Build walls/doors for the base. Only the team can go through the door, or step on the plates to buy things. Create plates that can be stepped on, to be bought by one team. These then disappear and create walls.
Today we finished our bases. We then began creating our first tool. We will finish this tool tomorrow. As a little challenge before tomorrow, try and have the output print "CLICKED" when you click your mouse while your tool is enabled. Try and figure out how to do this using ROBLOX Documentation:
https://create.roblox.com/docs/reference/engine
https://create.roblox.com/docs/reference/engine/classes/Tool
I've attached today's code below for the Tool Script. Let me know if you guys have any questions about anything we covered today. Enjoy your day, and see you tomorrow!
Code:
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local TopPart = Tool:WaitForChild("Part")
Tool.Equipped:Connect(function()
TopPart.ParticleEmitter.Enabled = true
end)
Tool.Unequipped:Connect(function()
TopPart.ParticleEmitter.Enabled = false
end)
--When you click your mouse on your tool, have it print "CLICKED"
--Try and figure this out using ROBLOX documentation
Week 9
Lesson 9
REVIEW DAY
Answer questions regarding students final projects, help with them
Today we finished creating our weapon. We created a light saber with a swing animation. Tomorrow you guys will work on your games and we will show each other what we created at the end of class. Please let me know if you guys have any questions about anything we covered today. I've attached my tool as an RBXM file. Enjoy the rest of your day, and see you tomorrow.
Week 10
Lesson 10
FINAL PROJECT PRESENTATION DAY
The students will create their own program from what they have learned throughout the class. Upon completion the projects are demonstrated by their creators.