How can I Hide UI/GUI after some seconds

What do you want to achieve?
I want that UI/GUI to auto-hide after some seconds but i’m still not that good at UI/GUI scripting so this is making me stay confused…

What solutions have you tried so far?
Devforum, but i didn’t find anything useful for what i need…


local players = game:GetService('Players')
local RS = game:GetService('RunService')

local plr = players.LocalPlayer
local gui = script.Parent
local guiAreas = workspace:WaitForChild('SinisTest')

local param =
param.FilterType = Enum.RaycastFilterType.Whitelist

	local char = plr.Character
	if not char then return end
	param.FilterDescendantsInstances = {char.PrimaryPart}
	for _, area in ipairs(guiAreas:GetChildren()) do
		local overlap = workspace:GetPartsInPart(area, param)
		if #overlap > 0 then
			gui[area.Name].Visible = true
			gui[area.Name].Visible = false
1 Like

Assuming gui is a ScreenGui, you can simply turn the Enabled property on or off to make the gui appear and vice versa. Hope that helps you figure out what to do!

But that isn’t the issue that i’m having… Visible already does what i want it to do, i just want the interface to hide after for example 5 seconds or so.

I think I understand now. Since you run this every frame, you can probably create a system using os.clock(). Something like…

local usedTime = os.clock()
local maximumHoldTime = 5

	if os.clock() >= usedTime + maximumHoldTime then
		-- it's been 5 seconds!

Hope this helps!

Are you talking about;

local GUI = game:GetService("Players).LocalPlayer:WaitForChild("ScreenGui")
GUI.Visible = true
GUI.Visible = false

or if the UI or GUI is not being used like no longer in focus? You could use Button/GUI.MouseLeave and use tick and when it reaches a certain value then you hide the UI/GUI. UserInputService could also work, I think there’s something there that you could use.


Best I could come up on a whim.

I could use that, but not sure on how to implement that into the code i wrote…

To make sure, you want the auto-hiding feature to apply to gui[area.Name], correct?

Yup, to apply to gui[area.Name] since i have more areas each with their respective Frame and TextLabel.

if #overlap > 0 then
	gui[area.Name].Visible = true
		local cancel = false
		for count = 0, 50, 1 do
			if gui[area.Name].Visible = false then cancel = true break end
		if cancel == true then return end
		gui[area.Name].Visible = false
	gui[area.Name].Visible = false

Made in a hurry, but I hope it helps. You essentially just need to wait 5 seconds and make sure the gui hasn’t been turned off in that time. There are probably better ways to do this though…

That didn’t work… but don’t worry i’ll try to find a fix to that issue.

I just found a solution myself, so i could say that this is solved!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.