Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to Properly Use MenuOpen() and MenuClosed() Events?

Right now I am working on making it so if you open the escape menu, your torso becomes anchored, not allowing you to move. However, when looking on the wiki of how to do this, there are no examples. Here's what I have so far:

function MenuOpen()
game.Players.LocalPlayer.Character.Torso.Anchored = true
end

function MenuClosed()
game.Players.LocalPlayer.Character.Torso.Anchored = false
end

I know this is not the proper setup of a function, but I am not sure what it is for this instance. Also, where would I put this Local Script? StarterPack? StarterPlayerScripts? Please help!

1 answer

Don't use the wiki examples for everything, try out stuff for yourself. These are functions you made. Since you are accessing game.Players.LocalPlayer, you will need to use a local script for this. Finally, those functions will not run on their own... add something like below to your script.

open = false -- your boolean for checking whether the menu is already open or not
function ToggleMenu()
	if(open) --if the menu is open, then close it
		game.Players.LocalPlayer.Character.Torso.Anchored = false
		open = false
	else --otherwise lets open the menu!
		game.Players.LocalPlayer.Character.Torso.Anchored = true
		open = true
	end
end

GUI_Thingy_Here.MouseButton1Down:connect(ToggleMenu) --enter the hierarchy from game.StarterGui to the textbutton or whatever you are checking to see if the mouse clicked

***If anything doesn't work or you are still clueless please let me know!

This discussion is preserved as it was. New answers, comments, and votes are closed.