Refitting UI on Different Resolutions

I’m making an anti-exploit that involves watching a player and their inputs via GUIs and camera work. One of these inputs is the position of the player’s mouse on their screen. The difficulty comes in accurately converting/representing the position of the player’s mouse on a different player’s screen if they each have different resolutions.

I’ve tried dividing the mouse’s position by the resolution to get UDim2 Scales X and Y, but I’ve found that with the bigger in difference the two resolutions are as well as how far from the middle of the screen the mouse is, the more skewed the result is, and thus less accurate. Examples being:

Summary

Similar Resolutions (goal):


Smaller Resolution (fail):

Larger Resolution (fail):

Repro Baseplate File:
Inaccurate Mouse Replication Repro.rbxl (18.4 KB)
Instructions:
Test > 2 Players > Start

TL;DR: how do i make a UDim2 point on one resolution translate to fit another different resolution?

1 Like

Currently, it appears to me that the point of your system is to see the actual point which the mouse is pointing to, not where it is on the screen. I, therefore, modified your place to get their mouse world position using:

game.Players.LocalPlayer:GetMouse().Hit.p

and then I used WorldToScreenPoint to get the on-screen position of the point so I can position the little red marker.

local Camera = game.Workspace.CurrentCamera
local Vector, OnScreen = Camera:WorldToScreenPoint(TheirMouse3DPosition)
				
if OnScreen then
	Representation.Position = UDim2.new(0, Vector.X, 0, Vector.Y)
end

Updated Place: Inaccurate Mouse Replication Repro.rbxl (18.8 KB)

To me it appears that with these modifications your system now works as intended. Please tell me if I misunderstood your intentions with the system. :+1:

https://gyazo.com/cde502364fdfae6a45d715d8babcfee8

This is impossible if you’re trying to get them to placed on the same thing just by using UDim2. An illustration of why this is impossible is that on different resolutions, you can see different amounts of things, so I could have my mouse over something which simply doesn’t show up on the other resolution.

If you’re looking for it to be placed in the same position relative to the size of the screen…

local mousePosition = Vector2.new(Mouse.X, Mouse.Y)
local player0ScreenSize = Camera.ViewportSize
local player1ScreenSize = Camera.ViewportSize

local newPosition = Vector2.new((Mouse.X/player0ScreenSize.X)*player1ScreenSize.X, (Mouse.Y/player0ScreenSize.Y)*player1ScreenSize.Y)