Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Remove() / Destroy() PlayerGui?

I need help destroying 2 player guis! I have 1 playergui (named "Buttons") w/ nothing to know about and another one named "TeleportGui", it has a TextButton inside it. It is named "Ready" I want when I click "Ready" every single PlayerGuis will get removed or destroyed.

Below is a local script inside the textbutton.

-- We need this script to destroy all player guis!!!!

-- Local Script inside the button
local clicked = false

script.Parent.MouseButton1Down:connect(function()
    if clicked == false then
        clicked = true
        local timer = 10 -- timer is 10 seconds
        local p = game.Players.LocalPlayer
        while timer > 0 do -- while the timer is bigger than 0 subtract 1, every second
            wait(1)
            timer = timer - 1
            p.PlayerGui.TeleportGui.TeleportGui.Close.Text = "READ DESC. ("..timer..")" -- changing the text of the button to the cooldown, and indicates the seconds remaining till the gui is removed
        end
        p.PlayerGui.TeleportGui:Destroy()
    end
end)

This is not working! Help!

2 comments

1

You didn't specify the problem with the script? What does it do? Does it work partially or not at all? Is there an error in the output?

0

I have edited it

1 answer

✓ Accepted answer

Instead of p.PlayerGui.TeleportGui:Destroy() you need to get ALL of the players guis, this can be accomplished by the following script.

for _, players in pairs(game.Players:GetChildren()) do -- Get the players
        players.PlayerGui.TeleportGui:Destroy() -- Destroy the Guis
end

Your final script would look like this

local clicked = false -- debounce

script.Parent.MouseButton1Down:connect(function() -- Remove button clicked
        if clicked == false then
        clicked = true
                for _, p in pairs(game.Players:GetChildren()) do -- Get players
                local timer = 10 
                        while timer > 0 do -- Dont continue until timer gets to 0
                        wait(1)
                        timer = timer - 1
                        p.PlayerGui.TeleportGui.TeleportGui.Close.Text = "READ DESC. ("..timer..")" 
                        end
                p.PlayerGui.TeleportGui:Destroy() -- Destroy the guis
                end
        end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.