So I want to find a way to make it so that I can set the size of a UI frame with any random number.

For example, if I had a UI frame that is .5 in X-Scale and I had 500 out of 500 that would be .5 on the frame because that is 100% of the UI’s size that I want to set it to.

Another example is if I had 200 out of 500, it would be 0.2 on the UI however, if I have numbers that are greater than 500, like 400 of 870, how would I find the 0.0 - 0.5 number that would fit in the UI frame. Where 870 of 870 would be .5, 400 and 870 should be variable.

I’m not sure if this makes sense, but hopefully, somebody can help me out here.

local viewsizeX,viewsizeY = 1920,1080 -- replace them with camera.ViewportSize.X and .Y respectively
local x,y = 200,500
local scaleX,scaleY = x/viewsizeX,y/viewsizeY

yes!! thank you this was it. a big help, I’ve bee trying to solve it all of yesterday haha, appreciate you very much.
i must ask, assume that I wanted to set the max value to something other then .5 but use the same numbers what value would I change??

*2 is the .5 part. basically it’s just x2 because you need to double .5 to make it 1.
If you wanted to change .5 to .75 or any other number the simplest method would be to divide the number with 1 (e.g. 1 / .5 = 2) so for .75 would be 1 / .75 = 1.33 so the sum would be

Sorry for the late reply.
I’m still a little confused on what your trying to accomplish to be honest so I don’t know if this is exactly what your trying to do but try this:

local BaseNumber=2
local MaxNumber=870
local ChosenNumber=400
local Result=(BaseNumber/100)*(ChosenNumber/(MaxNumber/100))
Result=math.floor(Result*100)/100 -- Round the number to 2 decimal places
print(Result)
--[[
prints 0.91
]]

I think you have a slight misunderstanding on what they were showing you.

The code they were showing, contained camera.ViewportSize.X and such.
This is not an actual viewportframe, but rather ViewportSize is a Vector2 containing the LocalPlayer’s screen size.

Now, to answer your question…

local cam = workspace.CurrentCamera
local X,Y = cam.ViewportSize.X,cam.ViewportSize.Y
function convertToScale(XSize,YSize)
return UDim2.new(XSize/X,0,YSize/Y,0)
end
local GX,GY = 10,10 --The offset size of GUI
local newSize = convertToScale()

Did I understand your question right? This code will convert GUI Offset size to scale.

So the code I gave you above is correct for the purpose and gives the correct result:

400 of 900 = 44.4%

1.9 = 100% so 1% = 0.019

44.4% = 0.84

0.84 is what the code shows as the result when these numbers are input:

local BaseNumber=1.9
local MaxNumber=900
local ChosenNumber=400
local Result=(BaseNumber/100)*(ChosenNumber/(MaxNumber/100))
Result=math.floor(Result*100)/100 -- Round the number to 2 decimal places
print(Result)
--[[
prints 0.84
]]

er it does not appear like it. @ZombieCrunchUK got it. look at what they wrote as I’m not sure how else to explain it. I’m not trying sizes, I’m trying to get a percent of a frame that is two numbers.