Detect when the player opens/closes the leave/reset/resume prompt

I’m attempting to detect when the player opens the settings or leave prompt, but it seems that my script is only detecting when they open it, but not when they close it. This is my setup.

local uis = game:GetService("UserInputService")
local content = script.Parent

uis.InputBegan:Connect(function(keyData,event)
	if(keyData.KeyCode == Enum.KeyCode.Escape and event) then
		content.Visible = not content.Visible
	end
end)
3 Likes

There’s actually native events for doing this which you should use over UserInputService. Those two come from GuiService: MenuOpened and MenuClosed.

The way GameProcessedEvent (the second parameter in most UserInputService functions, such as InputBegan) works is that it’s true if the engine is internally observing that input. The menu uses the escape key, so naturally it also has hold of that input.

For this case, you also need to account for the fact that the menu can be closed without users pressing the escape key such as through the aforementioned reset and resume modals.

I haven’t tested these two in a while so I’m not confident of their full function and if they also only check for the escape key or if they catch any and all opens/closes as well, but give them a try.

5 Likes

This works a lot better.

local guis = game:GetService('GuiService')

guis.MenuOpened:Connect(function()
	script.Parent.Visible = true
end)
guis.MenuClosed:Connect(function()
	script.Parent.Visible = false
end)

1 Like

First off this topic is 2 years old. Second off, your reply says This is a lot better when you just put the script for the exact thing he linked.

2 Likes

First off this topic is now 4 years old. Second off, it is much more concise and clear.

1 Like

you are truly an inspiration that I really do respect, man I hate people who “goo goo ga ga look at this roblox devforum reference that will take 20 hours to read instead of me just simply giving you the code you need WAAAAHHHH”

1 Like

you shouldnt hate people that encourage more learning through independent work rather than with an inspiration in front of you, these 2 ways of learning can vary in effectiveness depending on the person trying to learn. the first person to reply just gave the documentation for what the OP had to use, which turned out just fine for him. the second person, he provided a simple script using that, which almost everybody can do, as its less than 10 lines of code. they both helped the OP as much as they thought they needed to. also, stop glazing

you are clearly a “WAAAHHHH”-er and not an inspiration to the future of roblox. I could write this huge essay argument but I am simply too lazy to

get your scripting game up if you really need to copy 10 lines of code. Personally Id rather read the docs to know how to actually use something rather than using a script that if it works id rather not touch it.

Reading the docs is only for useful stuff, literally who will ever use this function again other than for bluring the screen or afk farming or whatever. Also, it’s really funny that you’re insulting my scripting skill. I could throw an insult back, but again, too lazy. To settle this, how about a scripting competition? See which learning style really is better. Will you accept my challenge, or be a coward and run away?

you really got me with the scripting competition bro, but i guess im just a little coward :sweat:. But if you thought about it a little bit, theres 2 things to keep in mind: 1. you cant call certain things more useful than others, if everything has their own purpose, because you could call raycasting more important because it has more use cases, but you cant replace MenuOpened with it… 2. Literally for roblox scripting people had to read the docs at least in some form, even though the programming language is derived on Lua, as it clearly has its specific functions,events,methods etc, as seen in this post…

and by the way i didnt say you should read the docs, i just said that some people have a better time learning something through the docs rather from a script from the devforum, mainly because ive been there before, so if you really want to use scripts from the forum, why not just say it? i never forced you to learn any other way, i just told you that people that give links to the docs instead of providing a script sample arent people who

1 Like

there have been others before you to say “copy and pasting code iS BaaAAADDDD for learning!!! YOU MUST READ THIS 50 PAGE DOC TO LEARN A SIMPLE FUNCTION!!!” Which is why I said this. I doubt literally anyone would prefer getting a link to the doc instead of just getting the code that works for you, which you can then use to look up the doc if you want to read more about it, whereas with the doc, you are forced to read the 50 pages to get the code you wanted, when you just wanted the code in the first place.

There are 2 things for YOU to keep in mind.
1st - Logical
2nd - Thinking

things necessary for scripting. No wonder you didn’t want to do the competition.

i dont get why you exaggerate a doc so much bro… its literally 3 sentences → use case → script sample (not always)
scripting isnt just about getting something to work… its about knowing how to do it, yourself, and again, you are trying so hard to prove a point you arent even telling the truth, i never said copying code is bad, i said stop telling people that want to learn by themselves through docs are babies.

average 50 page doc to make you learn a simple function:

1 Like

You are an inexperienced programmer with a huge ego, calm down a bit :sweat:

1 Like

oh you sure know everything about me, but judging by the way you used your brain to try help other people in scripting support, i doubt you know more than me, so we can be two dumb buddies if you want

its not worse, because nobody said youre supposed to give code, people help as much as they can and thats it. if youre not supposed to ask for scripts in here, dont always expect to find someone that gives them, its not worse they dont just write them for you, doesnt matter how simple they are

did you even read what I said?? This response doesn’t even correlate, like you were answering something else. What does the first part even mean?? Some attempt at an insult…? I really don’t know. I don’t need to know you to know if you say something dumb lol, but if you say enough dumb things you might as well be a dumb person.

As for the second part, oh why must there always be a second part, line breaks bore me. Can’t I just write a paragraph and have it be over with? Links are worse because of the logic I gave, if you choose to disregard that then lets end this pointless argument, you cant reason with someone who doesnt have the brainpower to understand reason, and it’s getting boring. Sure, you make a valid point about people giving links being the standard, learning is important for scripting. Which is boring, people like rzc are the sunshine through the cracks of a convoluted and ruthless world. Code will always be better than links, because code works, code is easy, code is learnable and searchable. Links are hard, links are time consuming, links are one way. You can get the link from code (while also having code). You can get the code from a link, (but you wont get the code until you spend 2 hours reading about something you will never use again).

Although I do agree, links are useful for stuff like raycasting. Even better, youtube tutorials. This forum, however, is not raycasting. Get better vocabulary, “glazing” isn’t a good variable name

dude when I hit “send post” I started re-reading what I sent and only halfway through you started typing like what the bruh?? Did you just skim through my message what happened?

i cant keep doing this bro, just code whatever way you want, if you only want scripts then go for it, say weird stuff like that, my whole point was to not glaze someone over 10 lines of code but its alright ive had enough. you win lil bro

thats actually really funny LOL, good one

you a real one bro, good luck on your scripting journey

1 Like