ViewportSize returning 1,1 only

I need to get the ViewportSize in order to convert from offset to scale, but ViewportSize is only returning 1,1 and not the pixel count of the screen.
I have tested this both on the client, the server, and on the clients in the client server testing environment


This is also inconsistent. In my game where I first realized this, ViewportSize returned the normal value when testing normally, but one on the client side of the server & clients testing environment. But in the game with nothing in it (and newer) it is returning 1,1 always.

I also found this older thread about viewport size in general, but it says that it will return the correct value on the client, which is not true (at least not anymore).

Did this recently change?

Are you printing the viewport size straight away when running the local script?

For some reason it takes some time before the Camera.ViewportSize is set so you can just wait for that to happen like this

local camera = workspace.CurrentCamera

print(camera.ViewportSize) --> 1, 1
camera:GetPropertyChangedSignal("ViewportSize"):Wait()
print(camera.ViewportSize) --> 1109, 792
3 Likes

Wow that is very nice. I guess the inconsistency was because it was in a module script which was initialized in the testing environment after the ViewportSize change and else before. I will put the wait in a conditional as it will wait indefinitely if it correctly recieved the first time.

local ViewportsizeX = workspace.Camera.ViewportSize.X
if ViewportsizeX == 1 then
	workspace.Camera:GetPropertyChangedSignal("ViewportSize"):Wait()
end
ViewportsizeX = workspace.Camera.ViewportSize.X

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