The problem here is that Mouse.Hit is a CFrame value while the position of a gui is a UDim2 value, and those two do not match well. For this, you will have to use a UDim2 value. The basic UDim2 value can be summed up as such:
Udim2.new(x_scale,x_offset,y_scale,y_offset)
We can access the x offset and the y offset of the mouse with the X and Y properties of the mouse.
1 | local mouse = game.Players.LocalPlayer:GetMouse() |
For example, I can have a gui follow my mouse with either the mouse.Move event or the renderstepped event of the Run Service.
1 | local gui = script.Parent |
2 | local mouse = game.Players.LocalPlayer:GetMouse() |
3 | local rs = game:GetService( "RunService" ) |
4 | rs.RenderStepped:Connect( function () |
5 | gui.Position = UDim 2. new( 0 ,mouse.X, 0 ,mouse.Y) |
However, in your case of the Mouse.Button2Down event, the same principles can be applied
1 | mouse.Button 2 Down:Connect( function () |
3 | popup.Position = UDim 2. new( 0 ,mouse.X, 0 , mouse.Y) |