GUI Text Not Lining Up Correctly

I created a currency GUI that tells the player how much money they have. In studio, it works fine, even with larger numbers. The numbers scale down and they shift left to the boundary. In the game, the numbers scale down as well when they get large, but they are not shifting to the left. I need to re-center the text when it is updated.
In Game:
Screen Shot 2020-03-22 at 8.36.30 PM
In Studio:
Screen Shot 2020-03-22 at 8.44.25 PM

Code:

script.Parent.Enabled = true

if script.Parent.Parent.Parent:FindFirstChild("Credits") then
	print('credits are', script.Parent.Parent.Parent.Credits.Value)
	script.Parent.TextBox.Text = script.Parent.Parent.Parent.Credits.Value
end

local function updateCredits()
	script.Parent.TextBox.Text = script.Parent.Parent.Credits.Value
end
script.Parent.Parent.Parent.Credits.Changed:Connect(updateCredits)

Edit: Even when there is 0 currency in-game, the value is shifted way to the right

Can we see what updateCredits does internally? That might be helpful.

Edit: Whoops, misread - I thought that was the function you use to shift the text. Where is the function that does this? The code snippet you provided doesn’t show the code that is causing the problem…

I don’t have a function to shift the text, it should just do it automatically if I have TextScaled set to true, right? And it turns out it is shifting it even if the text is not increasing in length.

Is the TextXAlignment set to Left?

It is not, but I want it to be centered for aesthetic purposes. It looks like the textbox is shifting itself to the right when I start the game for some reason, I don’t think it has to do with alignment because the textbox in studio doesn’t go beyond the background behind itself.

Are you using the scale or offset for the Position/size of the textLabel?
If you are using the offset, it is based off of pixels, so I’m assuming in game you are on a different screen size so it is shifted differently.

If you use Scale only it would be in place no matter the screen size.

1 Like

I am using scale for position and offset for size for all of the GUI elements. I will try switching to all scale

That would explain it! You can resize your screen inside of studio to test it without having to join the real game also.

1 Like

Yeah, that was definitely the problem. Thank you. How can I convert the offset to a scale value easily?

Hmmm, I’m not sure if there is an easy way.
One thing that comes to mind is running a line of code that would calculate the amount of pixels it currently consumes compared to the pixels that the parent gui has, and use the percentage it takes of its parent.

Or do it manually.

Here is something I wrote up which will resize any guis size to use scale only and keep the same size. Make sure when you run this code, the screen is on a good resolution where all the guis are how you want them.
you can change the refence of the first variable guiObject to the gui you want to resize.

local guiObject = -- refernce the gui you want to resize
local parentGui = guiObject.Parent

local xPixels = guiObject.AbsoluteSize.X
local yPixels = guiObject.AbsoluteSize.Y
local parentXPixels = parentGui.AbsoluteSize.X
local parentYPixels = parentGui.AbsoluteSize.Y

guiObject.Size = UDim2.new( (xPixels/parentXPixels), 0, (yPixels/parentYPixels), 0)
1 Like

Thank you for this! I’ve actually found a plugin that does it pretty seamlessly, however. Here it is if you want to take a look at it: https://www.roblox.com/library/332927999/GUI-Scale-Offset-Converter