Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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!

Ad

Answer this question