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)
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.
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)