Basically, when you right click, a gui will appear right next to the mouse. I tried setting the UI position to the mouse position and offessetting it by its size but it just won’t work due to ui.position only changing its position relative to its parent element.
I figured to only way to achieve this was to use absolute position but you cannot edit absolute position
check if the the frame size + mouse position is over the size of the screen
Explorer:
Local script:
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local Mouse = Players.LocalPlayer:GetMouse()
local Frame = script.Parent:WaitForChild("Frame", math.huge)
UserInputService.InputBegan:Connect(function(Input, GameProcessed)
if GameProcessed then
return
end
if Input.UserInputType == Enum.UserInputType.MouseButton2 then -- you can do it for mobile too
local ViewportSize = script.Parent.AbsoluteSize
local FrameSize = Frame.AbsoluteSize
local AnchorPoint = Vector2.new(0, 0)
if FrameSize.Y + Mouse.Y > ViewportSize.Y then
AnchorPoint += Vector2.new(0, 1)
end
if FrameSize.X + Mouse.X > ViewportSize.X then
AnchorPoint += Vector2.new(1, 0)
end
Frame.AnchorPoint = AnchorPoint
Frame.Position = UDim2.fromOffset(Mouse.X, Mouse.Y)
end
end)