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

How to destroy a GUI in a filtering enabled place?

Asked by 6 years ago

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)

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.
0
I'm a bit confused. I put both of your new scripts, client and server both into lighting. I'm not sure if I was supposed to do that but I'm assuming I wasn't because the GUI isn't being deleted. Ultimate_Piccolo 201 — 6y
0
Ah, I forgot something. It's fixed now. If you have more problems, hmu on ROBLOX. AdministratorReece 193 — 6y
Ad

Answer this question