TextFits not working

Server script (summarized):

		local function instancelabel(parent)
			
			for _,destroy in pairs(parent:GetChildren()) do

				if destroy.Name == 'OresRequired' then
					destroy:Destroy()
				end
			end
			
			local frame = Instance.new('Frame')
			local UIListLayout = Instance.new('UIListLayout',frame)
			local tablePos = 1
			frame.Size = UDim2.new(1,0,0,45)
			frame.Name = 'OresRequired'
			frame.Position = UDim2.new(0,50,0.8,0)
			frame.BackgroundTransparency = 1
			frame.Parent = parent
			UIListLayout.FillDirection = Enum.FillDirection.Horizontal
			UIListLayout.Padding = UDim.new(0,150)
			
			for count=1,2 do
				local Textlabel1 = Instance.new('TextLabel')
				Textlabel1.Size = UDim2.new(0,450,0,50)
				Textlabel1.TextColor3 = Color3.new(0,0,0)
				Textlabel1.Name = 'Textlabel'..tostring(count)
				Textlabel1.BackgroundTransparency = 1
				Textlabel1.Font = Enum.Font.FredokaOne
				Textlabel1.TextSize = 30
				Textlabel1.Text = ''
				Textlabel1.TextWrapped = true
				Textlabel1.AutomaticSize = Enum.AutomaticSize.None
				Textlabel1.Parent = frame
			end
			
			local labels = {frame.Textlabel1,frame.Textlabel2}

			for resourceName,required in pairs(OresTable[1]) do
				local currentLabel = labels[tablePos]
				currentLabel.Text ..= tostring(required)..' '..resourceName..'   '

				if tablePos == 1 then
					tablePos = 2
				else
					tablePos = 1
				end

			end
-- relevant parts start here
			for _,label : TextLabel in pairs(labels) do
				while label.TextFits == false do label.TextSize -= 2 end
			end
			
			if labels[1].TextSize < labels[2].TextSize then
				labels[2].TextSize = labels[1].TextSize
			elseif labels[2].TextSize < labels[1].TextSize then
				labels[1].TextSize = labels[2].TextSize
			end
--relevant parts end here
		end

		instancelabel(textbutton.Parent)
		for _,player : Player in pairs(Players:GetChildren()) do
			instancelabel(player.PlayerGui.ShopUi.Main.Base[UpgradeType].Main)
		end

I am trying to make a TextScaled-like system to make my text fit the textlabel, yet this code doesn’t work at all (relevant parts).

I’ve tried many solutions, printing a TextFits (apparently it prints true while it is false when you manually select the textlabel in explorer), permanently looping the relevant parts section to see if it is different anywhere, and it does seem to do it correctly when I switch to the server with the permanent loop, do I need to use a local script to set this?


The ‘1’ at the end of the first textlabel and closest to the green button is supposed to say ‘1 Gold’ and the text is supposed to get resized by my script to fit it in.
Please help

I ended up just using a free script called ‘SmartScale’, its pretty good

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.