-- Local Functions

local function waitForUpdate(stringLabel)
	if stringLabel._updating then
		repeat wait() until not stringLabel._updating
		
		wait()
	end
end

local function calculateLines(text, font, frameSize)
	local screenGui = Instance.new("ScreenGui", game:GetService("StarterGui"))
	
	local recursivelyCalculate = nil
	recursivelyCalculate = function(str, textSize, lines)
		local label = Instance.new("TextLabel", screenGui)
		label.Size = UDim2.new(0, frameSize.X, 0, frameSize.Y)
		label.Font = font
		label.TextSize = textSize
		label.Text = str
		
		if not label.TextFits then
			local words = {}
			local newStr1 = ""
			local newStr2 = ""
			
			for v in string.gmatch(str, "%S+") do
				table.insert(words, v)
			end
			
			for index, word in ipairs(words) do
				if index <= #words / 2 then
					newStr1 = newStr1 .. word .. " "
				else
					newStr2 = newStr2 .. word .. " "
				end
			end

			recursivelyCalculate(newStr1:sub(1, -2), textSize / 2, lines)
			recursivelyCalculate(newStr2:sub(1, -2), textSize / 2, lines)
		else
			table.insert(lines, str)
		end
		
		label:Destroy()
		
		return textSize / #lines
	end
	
	local lines = {}
	local textSize = recursivelyCalculate(text, frameSize.Y, lines)
	
	screenGui:Destroy(text)
	
	return lines, textSize
end
