sirrjohn Posted August 16, 2023 Share Posted August 16, 2023 (edited) I'm new to coding and I tried some ways with onPlayerQuit but no success. This is the code that is probably wrong since it didnt work... Problem is this gui stays open when you disconnect and rejoin the server. function quitPlayer () guiSetVisible ( GUIEditor.window[1] , false) showCursor ( false ) end addEventHandler ( "onPlayerQuit", root, quitPlayer ) This is the gui i want to close on quit GUIEditor.window[1] = guiCreateWindow(98, 46, 654, 450, "Weapon shop", false) Edited August 16, 2023 by sirrjohn Link to comment
Shady1 Posted August 19, 2023 Share Posted August 19, 2023 On 16/08/2023 at 19:48, sirrjohn said: I'm new to coding and I tried some ways with onPlayerQuit but no success. This is the code that is probably wrong since it didnt work... Problem is this gui stays open when you disconnect and rejoin the server. function quitPlayer () guiSetVisible ( GUIEditor.window[1] , false) showCursor ( false ) end addEventHandler ( "onPlayerQuit", root, quitPlayer ) This is the gui i want to close on quit GUIEditor.window[1] = guiCreateWindow(98, 46, 654, 450, "Weapon shop", false) You don't need to do this in onPlayerQuit, all data is already destroyed when the player exits the game. In your code, the panel is run at startup. If you set guiSetVisible to false it will not show up, but my advice is to create it when you need it and delete it with destroyElement Also, onPlayerQuit is a server event. The codes inside are client-side, so they don't work together. function destroyWeaponShop() --destroy function for shop if isElement(GUIEditor.window[1]) then destroyElement(GUIEditor.window[1]) GUIEditor.window = {} end end function doWeaponShop() --create function for shop GUIEditor.window[1] = guiCreateWindow(98, 46, 654, 450, "Weapon shop", false) end addCommandHandler("shop", function() if GUIEditor.window[1] then -- if window is exists delete destroyWeaponShop() else doWeaponShop() --if not exists create one end end ) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now