Make a folder that changes the name

I need help to do something like this:

Players clicks the button
Creates a Part named Part1

Players clicks the button again
Creates a Part named Part2

Players clicks the button again
Creates a Part named Part3

Is it possible? If yes, how?

local button = -- the button

local partNum = 1

local function createButton()
    local part = Instance.new("Part")
    part.Name = "Part" .. partNum
    part.Parent = workspace
    partNum += 1
end

button.MouseButton1Click:Connect(createButton)
1 Like