TextLabel not Changing Size Correctly

What do you want to achieve?:
I want to make a script that changes the size of a text label based on how long the text is every time the text changes.

What is the issue?:
The script I made doesn’t work. When I playtest the game the text label gets really small on X and normal size on Y and doesn’t change every time the text changes as it should.

What solutions have you tried so far?:
I have looked on here and on Google for solutions and have found some answers similar to what I need but not exactly what I need.

More info:
I have made a script that changes the text of the text label every time the stat in the leader stats changes. The stat is the player’s money. The script for changing the text works fine.

Here is the script for changing the size of the text label:

script.Parent.Changed:Connect(function()
	
	local textService = game:GetService('TextService')
	local newSize = textService:GetTextSize(script.Parent.Text, script.Parent.TextSize, script.Parent.Font, script.Parent.AbsoluteSize)
	local x = newSize.X
	local y = newSize.Y
	
	script.Parent:TweenSize(UDim2.new(0, x, 0, 40), "InOut", "Quad", .3, true)
	
end)

PLEASE LET ME KNOW IF I POSTED THIS CORRECTLY

Something doesn’t make sense
Why did you put script.Parent.Changed if it’s not a value

I think that’s the problem. Thanks! What should I use?

Well is it a local script?
Or a server script

It is a local script, not a server

And just to be clear, why aren’t you using text auto scale

Use auto scale for text, less work.

Change isn’t a value of a frame so that is the issue.

1 Like

And i just saw, you can’t change a size with four values

I have it so the text label is at the top right of the screen and has an image parented to it. I want the text to also be size: 30. It looks nicer that way.

Look

script.Parent:TweenSize(UDim2.new(0,0,40), "InOut", "Quint",0.3, true)

I have this script that works. It is for creating a notification and uses four values

script.Parent.MouseButton1Click:Connect(function()
	
local temp = game.ReplicatedStorage.NotificationTemp:Clone()
local newText = ("Thank you for you're feedback :D") -- Text

temp.Text = newText
	
local textService = game:GetService('TextService')
local newSize = textService:GetTextSize(temp.Text, temp.TextSize, temp.Font, temp.AbsoluteSize)

temp.Parent = game.Players.LocalPlayer.PlayerGui.Notifications.Frame
temp:TweenSize(UDim2.new(0, newSize.X+10, 0, newSize.Y+10), "Out", "Quad", .3, true)
wait(3)
temp:TweenSize(UDim2.new(0, 0, 0, 0), "In", "Quad", .2, true)
wait(.2)
temp:Destroy()
	
end)
1 Like

So from this, just change the values with the text size

Nice, no problem, if you don’t know just ask

I don’t understand what you are saying

Nvm just forget, hope you have a great day :smile:

what did you forget? I hope you have a great day too :smiley:

I fixed it so it changes when the int value changes and now it changes every time but it is still too small. We are getting closer to fixing this. Thx so much

Here is the new script. The problem now is that the text label is still too small

local stats = game.Players.LocalPlayer.leaderstats:FindFirstChild("Cash")

stats.Changed:Connect(function()
	
	local textService = game:GetService('TextService')
	local newSize = textService:GetTextSize(script.Parent.Text, script.Parent.TextSize, script.Parent.Font, script.Parent.AbsoluteSize)
	local x = newSize.X
	local y = newSize.Y
	
	script.Parent:TweenSize(UDim2.new(0, x, 0, 40), "InOut", "Quad", .3, true)
	
end)

Why is it still way too small? Does anyone know?

I remade most of the script. It also now changes the text of the TextLabel instead of another script doing that. It is a LocalScript.
Problem:

When I change the amount of money I have to 10 It correctly CHANGES the TextLabel’s SIZE and the TextLabel’s TEXT.

The next time I change the amount of money I have to 1000, it correctly CHANGES the TextLabel’s TEXT but NOT the TextLabel’s SIZE

Here is the script:

local money = game.Players.LocalPlayer.leaderstats.Cash

money.Changed:Connect(function()
	
	script.Parent.Text = money.Value
	
	local textService = game:GetService('TextService')
	local newSize = textService:GetTextSize(script.Parent.Text, script.Parent.TextSize, script.Parent.Font, script.Parent.AbsoluteSize)
	local x = newSize.X+10
	local y = newSize.Y+10
	
	script.Parent:TweenSize(UDim2.new(0, x, 0, y), "InOut", "Quad", .3, true)
	
end)