Roblox Studio Calculations Not Working?

Hello Developers
in my script, roblox is supposed to calculate the mouse location and the viewport size. but what happened is. Roblox studio gave the thing that i want to divide to the viewport size.

to calculate:
569/1366
247/767
Roblox Studio Answer:
= 569
= 247
Microsoft Calculator Answer:
= 0.4165446559297218
= 0.3220338983050847

script:

print(mousex / game.Workspace.Camera.ViewportSize.X,mousey / game.Workspace.Camera.ViewportSize.Y)
print(mousex,mousey)

mousex = :GetMouseLocation().X
mousey = :GetMouseLocation().Y
mousex/1366 = mousex
mousey/1366 = mousey

i fixed it by placing this line to client from server. and changing the script to UserInputService:GetMouseLocation().X / game.Workspace.Camera.ViewportSize.X,UserInputService:GetMouseLocation().Y

2 Likes

That’s because the server’s camera’s ViewportFrame has a resolution of 1x1 (1 pixel by 1 pixel), you need to get the client’s camera instead.

Additionally, you should be fetching the camera via the workspace’s “CurrentCamera” property, its value points/refers to the camera instance itself.

Try executing the following line of code in a server script.

print(workspace.CurrentCamera.ViewportSize)
1 Like