Hello!
I’m in the process of learning how to script. Every so often, I try and make my own script using what I’ve learned so far. Yesterday, I learned the use of return
, and decided to toss it in with the rest of the stuff I know to make a functioning block of code.
While I was doing this, I decided to try my luck at small tables and loops. To my extreme surprise, everything I scripted worked perfectly.
Now, I’m sure that because I’m quite new to this stuff, some of my code isn’t going to be efficient - which is why I’ve come to ask for tips on how to make it better:
-- the following code will instance 6 orange parts (each with a different position and material), which will then turn a shade of blue after 20 seconds
local function generatePart(material,position)
local part = Instance.new("Part")
part.Name = "Orange"..material.."Part"
part.BrickColor = BrickColor.new("Neon orange")
part.Material = material
part.Anchored = true
part.Position = position
part.Parent = workspace
print(part.Name.." was created.")
return part
end
-- this looks a bit inefficient to me; not sure
local glassPart = generatePart("Glass",Vector3.new(0,0,0))
local grassPart = generatePart("Grass",Vector3.new(5,0,5))
local slatePart = generatePart("Slate",Vector3.new(10,0,10))
local sandPart = generatePart("Sand",Vector3.new(15,0,15))
local brickPart = generatePart("Brick",Vector3.new(20,0,20))
local neonPart = generatePart("Neon",Vector3.new(25,0,25))
local partTable = {
glassPart,
grassPart,
slatePart,
sandPart,
brickPart,
neonPart
}
for i = 20,0,-1 do
print(i)
wait(1)
end
for i, v in pairs(partTable) do
v.BrickColor = BrickColor.new("Medium blue")
print(v.Name.."'s BrickColor was changed to Medium blue.")
end
Video of result
If there’s some feedback you’d like to share regarding the tables or loops, I kindly ask for you to explain it thoroughly (because I’m not too experienced with those).
Thanks!