Hi,
I am trying to make a menu that comes up after you right-click on a button. The way it works is that when it detects that you have right-clicked on a button, it gets the LocalPlayer’s mouse coordinates and puts the GUI at the coordinates and makes it visible. It kinda looks like the windows right-click feature. To close the right-click menu, I instance a Text Button that acts as a blocker (It takes up the whole screen). Whenever you press the blocker/anywhere on the screen, it will make the GUI go away and also make the blocker, invisible.
My problem is that the mouse coordinates don’t seem to be working.
The right-click menu is way off of the actual coordinates. Here’s what I have got:
-- Right Click Script
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local blocker = Instance.new("TextButton", ScreenGui) -- I have already defined ScreenGui. Thats not the problem. I can see the GUI. Its just not at the right location
blocker.Size = UDim2.new(1,0,1,0) -- Sets the size to take up the whole screen
blocker.BackgroundTransparency = 1 -- Sets Transparency to 0
blocker.Visible = false -- Makes it invisible
blocker.MouseButton1Click:Connect(function() -- Function for when the blocker is clicked
ScreenGui.RightClickMenu.Visible = false
blocker.Visible = false
end)
function ActRightClick(a) -- Function for when user right clicks. Dont worry about the argument.
blocker.Visible = true
-- Right Click menu code
ScreenGui.RightClickMenu.AnchorPoint = Vector2.new(0,1)
ScreenGui.RightClickMenu.Position = UDim2.new(mouse.X,mouse.Y) -- I am going wrong somewhere here (I think)
ScreenGui.RightClickMenu.Visible = true
end
for i,v in pairs(ScreenGui.Settings:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton2Click:Connect(function()
ActRightClick(v.Name) -- Dont worry about args
end)
end
end
I also want to know if there is a better way than using a blocker to block user input because I want the player to be able to press any other button (while the right click menu is open) without having to click twice. (once to close the right click menu and once to actually press the desired button)
If my method is bad please let me know. I couldn’t think of anything else. Thanks.