The size of my Image won't change

Hello!

I tried simplifying this script as simple as posible for me but still ran into this problem.

I tried to convert the Y size of my textlabel from Scale to offset.
The part were I converted the number works, but I can’t seem to figure out why the Y Offset size of the image does change but it becomes {1,0},{0,0}

local image = script.Parent

local function scaleToOffset(scale)
	local viewPortSize = workspace.Camera.ViewportSize
	print(scale)
	print(image.Size.Height.Offset)
	print(viewPortSize.Y)
	print(scale / viewPortSize.Y)
	
	
	return {scale / viewPortSize.Y}
end

local Y = scaleToOffset(image.Size.Height.Offset)
print(Y)

image.Size = UDim2.new(1,0,Y,0)

this is the output I’m getting for every print statement:

print(scale) = 200
print(image.Size.Height.Offset) = 200
print(viewPortSize.Y) = 356
print(scale / viewPortSize.Y) =)0.5617977528089888
print(Y) = 0.5617977528089888

Now when I convert the image with the plugin AutoScale Lite, it does give the same answer as what the statements print (0.562).

Could someone maybe help me?

Now thank you for reading this and I hope you have a wonderfull day! :upside_down_face:

1 Like

UDim2.new’s constructor’s looks like this: (scaleX, offsetX, scaleY, offsetY).

I think you’re trying to replace the scaleY with your newly converted offset value. Which is inputting it in the wrong parameters. So maybe you meant to do this instead?

image.Size = UDim2.new(1, 0, 0, Y)

Oh wait no, you also have another issue. Your function is returning a table and UDim2.new’s constructor will consider that as 0, which is giving you your wrong output! Remove the {} around your return value!

local function scaleToOffset(scale)
	local viewPortSize = workspace.Camera.ViewportSize
	print(scale)
	print(image.Size.Height.Offset)
	print(viewPortSize.Y)
	print(scale / viewPortSize.Y)
	
       -- REMOVE THE CURLY BRACKETS {}, you were returning a table, 
       --not a number
	return scale / viewPortSize.Y
end

Thank you for helping me!
:pray: :pray: :pray:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.