Jun 14 2019, 4:47 PM PST


You want to create an object, set all its properties, and then use it throughout your code without setting it up over and over again.


Use the Clone method.

local frame = Instance.new('Frame')
frame.BackgroundColor3 = Color3.new(1, 1, 1)
frame.BackgroundTransparency = .5
frame.BorderSizePixel = 0
frame.Size = UDim2.new(.25, 0, .25, 0)
for i, v in ipairs(game.Players:GetPlayers()) do
	local lframe = frame:Clone()
	lframe.Position = lframe.Position + UDim2.new(0, i, 0, i)
	lframe.Parent = game.Players.LocalPlayer.PlayerGui.Screen


First we created the Frame object and then set some of its properties. Then we had a loop and we cloned an instance of this Frame that had all its properties set, then changed its Position and Parent. This method of creating an object, and then using it later with the clone method is called templating (there isn’t an official name for this, I coined the term “templating” myself).

  • optimization
  • template