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:
In Studio:
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.
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.
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.
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)