How do I make my GUI disappear after a limited time?

  1. What do you want to achieve? I want this GUI to show up on screen for a limited time, but I want it to no longer show up after passing through the trigger brick.

  2. What is the issue? I can’t seem to find any basic way to achieve this. image

  3. What solutions have you tried so far? I’ve tried adding a repeat = false to the end of the script, to no avail.

I don’t know if this is the best way but my way is to make a debounce and never set it back to the value needed to trigger the event.

You should use a remote event and control the gui in a local script when the remote event is fired. Local scripts are perfect for making guis visible or invisible.

I think the solution is this one which requires a remote event that someone mentioned earlier.

GUI:

game.ReplicatedStorage.ShowGUI.OnClientEvent:Connect(function()
script.Parent.Frame.Visible = true
wait(5)
script.Parent.Frame.Visible = false
end)

Server:

local debounce = false
local Part = script.Parent
Part.Touched:Connect(function(hit)
if not debounce then
debounce = true
local B = game.Players:GetPlayerFromCharacter(hit.Parent)
if B then
game.ReplicatedStorage.ShowGUI:FireClient(B)
end
debounce = false
end
end)

I don’t fully understand the question, correct me if I am wrong.
If OP wants the UI to show up only once and never show up again, then this is my implementation of that code:

local Part = script.Parent

Part.Touched:connect(function(HIT)
    local B = HIT.Parent:FindFirstChild("Humanoid")
    if B then
        local Player = game.Players:GetPlayerFromCharacter(HIT.Parent)
        local ui = Player.PlayerGui.GUI3:FindFirstChild("Frame")
        if ui and ui.Archivable == true then
            ui.Visible = true
            ui.Archivable = false --we mark it so that it won't show up again while it isn't destroyed
            game.Debris:AddItem(ui, 5) --SELF DESTRUCTION IN 5 SECONDS
        end
    end
end)
3 Likes

Since this is just basically about the client and that Touched events are really controllable by the client anyways, you could just do it all in a local script where you detect that specific part if it’s available in workspace then either do one of the following:

  1. Disable the GUI by toggling the GUI’s Enabled property to false.
  2. Set the Visible property to false on the GUI objects you want to toggle off (like a Frame in your GUI3 object).
  3. Destroy the GUI completely with :Destroy().

Otherwise for a server-sided approach, you’re gonna have to use RemoteEvents. When the Touched event occurs, just get the player who touched the part then fire the client (player who touched the part) to do the action you want.

I also recommend using :Connect as I see :connect instead in the image, :connect is deprecated.

1 Like

This worked! Thank you for your help.

1 Like