So when you do this:
local screenX = game.Workspace.Camera.ViewportSize.X
local screenY = game.Workspace.Camera.ViewportSize.Y
function makerates()
local foodframe = Instance.new("Frame",script.Parent)
print(game.Workspace.Camera.ViewportSize.X)
foodframe.Size = UDim2.new(screenX*.05,screenX*.02)
foodframe.Position = UDim2.new(.5,0,.5,0)
end
makerates()
the print statement will give me the correct pixel count but when I do this:
local screenX = game.Workspace.Camera.ViewportSize.X
local screenY = game.Workspace.Camera.ViewportSize.Y
print(game.Workspace.Camera.ViewportSize.X)
function makerates()
local foodframe = Instance.new("Frame",script.Parent)
foodframe.Size = UDim2.new(screenX*.05,screenX*.02)
foodframe.Position = UDim2.new(.5,0,.5,0)
end
the print statement will always print out 1
If I remove the '.X' part from the end of the print statement, it will almost always give me 1,1 even though it shouldn't
What's wrong with ViewportSize and how do I fix it

2 comments
The parent argument to Instance.new is deprecated.
try doing wait(1) at the top of your script. iirc the ViewportSize prop isn't correct right when the game starts. like it doesn't account for the topbar offset