I want to hide Frame (GUI) when the user press somewhere else (Anywhere not on the Frame) like BedWars. I know how to code, so I just need an idea. I want to make it simple as possible. Thank you.
It would be helpful if you tried it yourself first and showed us an example.
Can you show us what you are doing?
As you have provided an example, all you would need to do is create an empty text button or image button the size of the screen (1,1 scale) and then listen to the .Activated
event. Make sure to only show this if another UI is currently enabled or else it would sink other mouse inputs.
In the example you posted, they simply made a frame containing all of the parented missions turn the visible setting in properties to false thus making its children also not visible
Thanks for the response. Yet I know that turning off the visibility of the Frame will make its children also not visible. What I want to know is when I should make the Frame not visible in what condition.
Sure This is my code:
-- Opens Advertise Frame
function OpenAdvertiseFrame()
AdvertiseFrame.Visible = true
end
-- Closes Advertise Frame
function CloseAdvertiseFrame()
AdvertiseFrame.Visible = false
end
-- Event Functions
AdvertiseButton.MouseButton1Click:Connect(function()
OpenAdvertiseFrame()
end)
AdvertiseFrame.MouseEnter:Connect(function()
isMouseInFrame = true
end)
AdvertiseFrame.MouseLeave:Connect(function()
isMouseInFrame = false
end)
Mouse.Button1Up:Connect(function()
if isMouseInFrame == false then
CloseAdvertiseFrame()
end
end)
Is this what you mean?
local framebutton = --- path to frame
frame.MouseButton1Down:Connect(function()
for i, v in pairs(frame:GetChildren()) do
if v:IsA("Frame") then -- Classname if it's a frame for example
v.Visible = false
end
end)
It selects all the children (anything parented to the frame) and checks if it’s class name is a frame for example and if it is it makes it not visible
alternatively you could use :GetDecendants() which would get all of the children below them,
What I want to do is:
When player click anywhere NOT on the Frame (in this case AdvertiseFrame), the Frame becomes not visible.
Ahhh Okay. So what bedwars did, is they have a background that acts as a button, which you can see as it is slightly translucent, but when you click this background they run the code.
local backgroundbuttonframe = --- path to background frame
local missionframe = -- missionframe path
backgroundbuttonframe.MouseButton1Down:Connect(function()
missionframe.visible = false
end)
My script does work. But there is a problem.
Even though I click children of the “Frame” (Select Load Method Button) the Frame becomes not visible. Other than that, it works.
I want to know how to fix this problem. And it there is any better ways to do this, please tell me.
Make sure the zindex of the loadmethod button is higher than the background
oh so is the background button frame a big frame that covers the whole screen? It’s like how @2jammers said. I was about to try. I will test it rn.
Alright, it should work hopefully
It didn’t work. I’m pretty sure even though there is something on top of the button, as long as user clicks where the button is, it activates.
I’m pretty sure that its overlapping your other frames, try increasing the zindex of your loading frames to a number that is above the background’s zindex
Yes I did changed the background zindex to -1
Check out this method
What you could do is whenever the player clicks, take the mouse position and use this function. Then loop through the instances and check if the frame is there, if it’s not you can hide the frame
local Players = game:GetService('Players')
local UserInputService = game:GetService('UserInputService')
local player = Players.LocalPlayer
local playerGui = player.PlayerGui
local frame = script.Parent.Frame
UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
if input.UserInputType ~= Enum.UserInputType.MouseButton1 and input.UserInputType ~= Enum.UserInputType.Touch then
return
end
local position = input.Position
local guiObjects = playerGui:GetGuiObjectsAtPosition(position.X, position.Y)
if not table.find(guiObjects, frame) then
frame.Visible = false
end
end)