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…
Code:
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 = OverlapParams.new()
param.FilterType = Enum.RaycastFilterType.Whitelist
RS.RenderStepped:Connect(function()
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
else
gui[area.Name].Visible = false
end
end
end)
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
RS.RenderStepped:Connect(function()
if os.clock() >= usedTime + maximumHoldTime then
-- it's been 5 seconds!
end
end)
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.
if #overlap > 0 then
gui[area.Name].Visible = true
task.spawn(function()
local cancel = false
for count = 0, 50, 1 do
task.wait(0.1)
if gui[area.Name].Visible = false then cancel = true break end
end
if cancel == true then return end
gui[area.Name].Visible = false
end)
else
gui[area.Name].Visible = false
end
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…