Roblox Basic Part and Model

Next, we'll dive into using Lua in Roblox Studio, focusing on the fundamentals of working with parts and models. We'll cover how to create parts using functions, change their properties, handle Roblox events, and combine parts to create models.

Using Functions in Roblox Studio

function createPart() 
   local part = Instance.new("Part")    
   part.Parent = game.Workspace 
   part.Position = Vector3.new(0, 50, 0) 
end 
createPart()

Object & Properties

local part = Instance.new("Part") 
part.Size = Vector3.new(4, 1, 2) 
part.BrickColor = BrickColor.new("Bright red") 
part.Parent = workspace

Events

local part = Instance.new("Part", workspace) 
part.Touched:Connect(function(hit) 
   print("Part was touched by " .. hit.Name) 
end)

Click and Touch Event

local clickDetector = Instance.new("ClickDetector", script.Parent) 
clickDetector.MouseClick:Connect(function(player) 
   print("Button clicked by " .. player.Name) 
end)

Working with Models

local model = Instance.new("Model", workspace) 

local part1 = Instance.new("Part", model) 
part1.Position = Vector3.new(0, 5, 0)
part1.Size = Vector3.new(4, 1, 4) 
part1.BrickColor = BrickColor.new("Bright red") 

local part2 = Instance.new("Part", model) 
part2.Position = Vector3.new(5, 5, 0) 
part2.Size = Vector3.new(4, 1, 4) 
part2.BrickColor = BrickColor.new("Bright blue")

If you found this tutorial helpful and would like to support my work, please consider buying me a coffee.

Thank you very much for your support!

Buy me a coffee