I’m trying to move the frame to be just to the left of the mouse cursor, but the ui grid layout of the scrolling frame that holds the buttons is causing the frame to be set to a specific distance to the left no matter what numbers I change in the script, the only thing that fixes it is deleting the uiGridLayout (Example Below):
Here is the script Im using for making the Frame visible based on the mouse click position, any help would be Great!
(The script is a local script inside of a button inside of a viewport inside of the scrolling frame)
local button = script.Parent
local frameName = button.Parent.Name -- Assuming the frame has the same name as the viewport
local frame = button.Parent.Parent.Parent:FindFirstChild(frameName)
local HomePage = button.Parent.Parent.Parent -- Parent of all frames
local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
button.MouseButton1Click:Connect(function()
if frame then
-- Hide all frames except the scrolling frame
for _, siblingFrame in ipairs(HomePage:GetChildren()) do
if siblingFrame:IsA("Frame") and siblingFrame ~= frame then
siblingFrame.Visible = false
end
end
-- Calculate mouse location relative to the button's position
local mouseLocation = UIS:GetMouseLocation() - button.AbsolutePosition
-- Calculate the new position slightly to the left of the mouse click position
local newPosition = UDim2.new(0, mouseLocation.X - frame.Size.X.Offset - 10, 0, mouseLocation.Y)
-- Tween the frame's position to the new position
local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local tween = TweenService:Create(frame, tweenInfo, {Position = newPosition})
tween:Play()
-- Toggle visibility of the clicked frame after the tween completes
frame.Visible = true
else
warn("Frame not found: " .. frameName)
end
end)