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
break
end
wait()
end
end
script.Parent.MouseButton1Down:Connect(function()
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)
AnimateTextFunction(NTBM,HMTTBM)
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 = UDim2.new(0,0,0,I*50)
LoadingPercentage = math.floor((I/HMTTBM)*100)
wait()
end
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"
end
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 = UDim2.new(0,0,0,0)
script.Parent.Parent.Parent.Multiplication_Table_List:ClearAllChildren()
local UIListLayOut = Instance.new("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
end
end)```
Thanks!