I have a script (local) that changed the player's main gui size to fit the 16:9 ratio. BUT, for some reason it goes crazy and keeps going between two sizes and won't stop.
Here's the script:
local width = 16 local height = 9 local parent = script.Parent.Main local running = false local storedSize = parent.AbsoluteSize local rs = game:GetService("RunService") rs.RenderStepped:connect(function () if running then return end storedSize = parent.AbsoluteSize if checkSize() then return end running = true parent.Size = UDim2.new( 1, -(storedSize.X%width), 1, -(storedSize.Y%height)) running = false end) function checkSize() if storedSize.X%width ~= 0 or storedSize.Y%height ~= 0 then return false else return true end end
I may have to do with how I make it get to the 16:9 ratio....
The math here doesn't make any sense.
%
is remainder after division. Why are you taking the remainder after division by 9
and making sure that's not 0
? That's 88% of Y values. For the % 16
, that's 94%.
Just set the height to 9/16
times the width, or the width to 16/9
times the height, or each to some middle ground:
-- Just ignore height and resize vertically based on width rs.RenderStepped:connect(function() local width = storedSize.X local height = width * 9 / 16 parent.Size = UDim2.new(0, width, 0, height) end)
-- Do some sort of in-the-middle of width and height rs.RenderStepped:connect(function() local size = parent.AbsoluteSize local mw = size.x / 16 local mh = size.y / 9 local m = (mw + mh) / 2 parent.Size = UDim2.new(0, m * 16, 0, m * 9) end)