Its suppose to destroying the GUI when you leave the room, but it's not...why?
local player = game.Players.LocalPlayer script.Parent.Touched:connect(function(player) if player.PlayerGui.DJPanel.MusicScreen.Visible == true then player.PlayerGui.DJPanel:Destroy() if player.PlayerGui.DJPanel.EffectScreen.Visible == true then player.PlayerGui.DJPanel:Destroy() if player.PlayerGui.DJPanel.Frame.Visible == true then player.PlayerGui.DJPanel:Destroy() end end end end)
Note: Giving us an error message (in Output window) makes it easier to figure out what's wrong. If you're testing online, press F9 for the Developer Console.
You have a local variable named "player" (line 1) and also an argument named "player" (line 3), which hides the local variable on line 1.
.Touched gives you a part, so you should probably make sure the part is part of the player.
If you Destroy DJPanel, you won't be able to destroy its children (but that'll be done automatically).
local player = game.Players.LocalPlayer script.Parent.Touched:connect(function(part) if part.Parent ~= player.Character then return end --part not from player if player.PlayerGui.DJPanel.MusicScreen.Visible == true then player.PlayerGui.DJPanel:Destroy() end end)
If you put the script in a Gui, be sure to change "script.Parent" to be the proper Part in the workspace.
The problem that you are having is quite easy to fix and is an honest mistake, everyone has made this mistake before. When a part is touched by a user, the body part that hits the object that was touched is a member of the player's character and is not within the player and is not the player. You are simply trying to destroy a Gui that is inside a body part and does not exist. You can easily fix this with the GetPlayerFromCharacter method.
In addition to this problem, you cannot have a localscript placed within a part that is in Workspace. I have fixed the script for you and this should work, if it does not, double-check your hierarchical structure. You are also attempting to destroy a single object 3 times, which will throw an error, I have also fixed that for you.
player = nil panel = nil script.Parent.Touched:connect(function(body) player = game.Players:GetPlayerFromCharacter(body.Parent) panel = player.PlayerGui.DJPanel if panel.MusicScreen.Visible == true or panel.EffectScreen.Visible == true or panel.Frame.Visible == true then panel:Destroy() end end)