Detect exactly when escape menu is closing

Here’s a script that can tell when you open and close the escape menu:

game.GuiService.MenuOpened:Connect(function()
	print("Opened escape menu.")
end)

game.GuiService.MenuClosed:Connect(function()
	warn("Closed escape menu!")
end)

Video: https://gyazo.com/270707db797b40d64d5b36f2e4b5f6c8

But the issue is, the closing event only fires once the menu has fully disappeared. The open event also doesn’t fire if it was already visible due to it not closing immediately.

Is there a reliable method of detecting exactly when it starts opening and closing?

The reason for this is because I want to be able to muffle ingame music, while the menu is open. If the transition waits for the menu to fully close, it will be muffled for too long.


I won’t be able to test anything because I won’t be home, but your help is still appreciated! If there’s no solution, I have a method in mind which would be incredibly hacky. It would work, but I would rather ask if anybody knows a better way!

3 Likes

You can wrap a while task.wait() loop in a coroutine and check if a coregui menu is open probably not the best way to do it but it works

Use input service for the esc key or if they are on a touchpad put in a button on it then if it gets clicked it is fired?

What would I be checking every moment in the loop? Some property of GuiService? I looked around and I only saw the MenuOpen and MenuClose events.

A button would be under the escape button, since it’s in coregui.

1 Like

Well it would work for pc players at least with UIS?

Doing that is part of my hacky method, if there’s no other solution. It would be detecting ESC, clicking near the menu button, pressing menu on a controller, etc.

1 Like

So if unfortunatly nobody knows, I guess I’ll have to go with my hacky solution. If it works, I’ll also post it here.

It’s been a while so I’m not sure, but last I remembered thr ESC key can’t be detected by UIS, at least in Studio.

Pretty sure it can, just that the process argument of InputBegan would be false. I’d have to ignore that.

Whatever workaround you came up with, you’re going to have to use that. The CoreScript responsible for firing the GuiService menu events only chooses to do so after the tween finishes and naturally you, the developer, can’t access any core items, therefore can’t change the timing of the signal fire.

2 Likes

User input service and check if its esc key i guess?

There’s more ways to toggle the menu though, so this won’t work.

1 Like

I think it’s called MenuIsOpen it’s a bool value

Didn’t see that property before, but it’s still following the wrong timing unfortunatly: https://gyazo.com/d65378350d74373d1cd741d6b5b0e086