I’m trying to have a frame anchor itself around my cursor when I click on it. My code works, but I’m having trouble having it connect where I want it to. I’m using the code below to anchor the frame, however, it is having weird results.
YandhiFrame.AnchorPoint = Vector2.new(cursor.Position.X.Offset/YandhiFrame.AbsolutePosition.X, cursor.Position.Y.Offset/YandhiFrame.AbsolutePosition.Y)
Gui Hierarchy
My Code:
-- References
local UIS = game:GetService('UserInputService')
local player = game:GetService('Players').LocalPlayer
local mouse = player:GetMouse()
local Hold = script.Hold
local Release = script.Release
local pc_screen = player.PlayerGui:WaitForChild('PC Screen')
local desktop = pc_screen:WaitForChild('Desktop')
local cursor = desktop:WaitForChild('CursorGUI')
local YandhiFrame = desktop:WaitForChild("YandhiFrame")
local YandhiDragButton = YandhiFrame:WaitForChild("DragButton")
local YandhiTab = YandhiFrame:WaitForChild("YANDHI")
local YandhiIcon = desktop:WaitForChild("Yandhi.zip")
local YandhiText = YandhiIcon:WaitForChild("TextLabel")
local YandhiButton = YandhiIcon:WaitForChild("ImageButton")
--Yandhi Tab Drag
YandhiDragButton.InputBegan:connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 and YandhiFrameDragged == false then
YandhiFrameDragged = true
YandhiFrame.AnchorPoint = Vector2.new(cursor.Position.X.Offset/YandhiFrame.AbsolutePosition.X, cursor.Position.Y.Offset/YandhiFrame.AbsolutePosition.Y)
while YandhiFrameDragged == true do
YandhiFrame.Position = cursor.Position
wait()
end
end
end)
YandhiDragButton.InputEnded:connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 and YandhiFrameDragged == true then
YandhiFrameDragged = false
YandhiFrame.AnchorPoint = Vector2.new(0.5, 0)
end
end)
Example of connecting where I don’t want it to:
I want the frame to anchor at the top, along the X-axis where the red button is, as a real OS.
If you need me to elaborate more I will do so.
Thanks!