I am attempting to destroy a GUI once you click a TextButton. I've tried this many ways, some of which worked in Play Solo in Roblox Studio but that do not work in the actual game. My most recent attempt was using a script in Workspace that cycled through all the player's backpacks to look for a script in the player's backpack that had a remove event. However, I'm new to filtering enabled and I don't understand why it doesn't work.
Normal Script in Workspace
for i,v in pairs(game.Players:GetPlayers()) do if v:FindFirstChild("Backpack")then v.Backpack.CloseGUI.CloseGUIs:FireClient() end end
Local Script in Starterpack that is the parent to the RemoveEvent
script:WaitForChild("CloseGUIs") script.Parent.Parent.PlayerGui.Shop.timema.Close.MouseButton1Click:connect(function() script.CloseGUIs.OnClientEvent:connect(function() script.Parent.Parent.PlayerGui.Shop:Destroy() end) end)
Hi there!
here's something I whipped up, it's annotated showing everything I do.
for i,v in pairs(game.Players:GetPlayers()) do if v:FindFirstChild("Backpack") then v.Backpack.CloseGUI.CloseGUIs:FireClient() -- Your server code end end --------- script:WaitForChild("CloseGUIs") script.Parent.Parent.PlayerGui.Shop.timema.Close.MouseButton1Click:connect(function() script.CloseGUIs.OnClientEvent:connect(function() script.Parent.Parent.PlayerGui.Shop:Destroy() -- Your client code end) end) ---------------------------------------- -- My server code: -- Place the Remote in Lighting. local function RemovePart(player, where) -- This is the function run by the RemoteEvent. where:Destroy() -- This is ROBLOX's new Destroy() function print() end -- end game:GetService("Lighting"):WaitForChild("CloseGUIs").OnServerEvent:connect(RemovePart) -- watches the remote for fires. ------- -- My client code: local lighting = game:GetService("Lighting") -- where is lighting? lighting:WaitForChild("CloseGUIs"):FireServer(script.Parent.Parent.PlayerGui.Shop) -- Fires the server -- This fires the remote to delete the player's GUI. -- You can use this for other things as well. If you ever want to remove anything, just do [client] -- game:GetService("Lighting"):WaitForChild("CloseGUIs"):FireServer(where.do.you.want.to.delete["?"]) -- replace the path in the FireServer(brackets) with the thing you want to destroy.