Is there a more efficient way to create this multiplication table generator?

I thought It would be a useful script to create a Multiplication table script. But since I am relatively new to Debouncing and coroutines I thought I might be able to improve this script, Can I?

Due note, this is made on a local script, would it be better to get the information on the server, and send it through a table to a client since the server might be able to handle it better?

local IsLoading = false
local LoadingPercentage = 0
local Active = false
local function AnimateLoadingText(NumberToBeMultiplied,HowManyTimes)
	while IsLoading do
		script.Parent.Parent.Parent.Status.Text = "Generating Table For "..NumberToBeMultiplied.."; "..HowManyTimes.." | "..LoadingPercentage.."%"
		if not IsLoading then
	if not Active then
		local StartingTime = tick()
		local NTBM = script.Parent.Parent.NTBM.Text
		local HMTTBM = script.Parent.Parent.HMTTBM.Text
		if type(tonumber(NTBM and HMTTBM)) == "number" then
			script.Parent.GenerateText.Text = "Close"
			script.Parent.Parent.HMTTBM.TextEditable = false
			script.Parent.Parent.NTBM.TextEditable = false
			Active = true 
			NTBM = tonumber(NTBM)
			HMTTBM = tonumber(HMTTBM)
			IsLoading = true
			local AnimateTextFunction = coroutine.wrap(AnimateLoadingText)
			for I = 1, HMTTBM, 1 do
				local MultiplicationObj = game.ReplicatedStorage.MultiplicationObject:Clone()
				MultiplicationObj.Multiplication_Text.Text = NTBM.." * "..I.." = "..NTBM*I
				MultiplicationObj.Parent = script.Parent.Parent.Parent.Multiplication_Table_List
				script.Parent.Parent.Parent.Multiplication_Table_List.CanvasSize =,0,0,I*50)
				LoadingPercentage = math.floor((I/HMTTBM)*100)
			IsLoading = false
			LoadingPercentage = 0
			local TotalTime = tick() - StartingTime
			script.Parent.Parent.Parent.Status.Text = "Multiplication Table for "..NTBM.."; "..HMTTBM.."| Total Time Taken Was: "..math.floor(TotalTime).." ~ seconds"
	elseif Active or IsLoading then
		script.Disabled = true
		Active = false
		script.Parent.Parent.Parent.Status.Text = ""
		script.Parent.Parent.HMTTBM.TextEditable = true
		script.Parent.Parent.NTBM.TextEditable = true
		script.Parent.Parent.Parent.Multiplication_Table_List.CanvasSize =,0,0,0)
		local UIListLayOut ="UIListLayout")
		UIListLayOut.Parent = script.Parent.Parent.Parent.Multiplication_Table_List
		script.Parent.GenerateText.Text = "Generate Single Multiplication Table"
		script.Parent.Parent.HMTTBM.Text = ""
		script.Parent.Parent.NTBM.Text = ""
		script.Disabled = false

The way that I look at multiplication tables are grid-like. Almost like the battleship games where you call A1, B1, etc. At its most basic state, it is comprised of rows & columns. This systematic ideology is one of the core fundamentals of tables. Knowing this, the row would be the numerical value that you want to find multiples for. The columns would be the index being multiplied to the row.

-- If you wanted to get all multiples in a range of 5x5. 
local x, y = 5, 5
for x=1, x, 1 do
    for y=1, y, 1 do
        -- Could create or label UI here
        print(x, y, x*y)
-- If you wanted to find a particular multiple if the user supplies a number
local x = 10 -- Number wanting to find multiples for.
local y = 5 -- Could make range a user input too. 

for y=1, y, 1 do
    print(x, y, x*y)

This isn’t actually a complete table since we lack 0. Even though it’s understood to be 0 at all times (0 * # = 0), it’s still listed in most textbooks. Unfortunately, we can’t index a 0 in a table since lua is weird like that. Real broski coders know that tables start at 0.

Hope this helps in some way.

1 Like

Ok, Thanks for the feedback, I will try and implement this :slightly_smiling_face: