Help with task.delay

is there a way to enable/disable gui’s using task.delay

ex: task.delay(1, GUI.Enabled, false)

and no i don’t want to do task.delay(1, function() GUI.Enabled = false end)

1 Like

You could make a function and input it as the parameter. Is this what you’re looking for?

local function TestFunction()
	print("hi")
end

task.delay(1, TestFunction)

ex: task.delay(1, GUI.Enabled, false)

This would be a great addition, but unfortunately it’s not a thing. The closest you will get is:

task.delay(1, function()
    GUI.Enabled = false
end)

Surprisingly, there aren’t really any downsides to using this anyway. Not sure what your use case is, but hopefully this helps.

damn really? that sucks hopefully roblox adds it soon

The closest thing you’ll get to something like that is with a custom function.

local function DelayProperty(dur, object, property, value)
	task.delay(dur, function()
		object[property] = value
		warn(property)
	end)
end

DelayProperty(1, GUI, "Enabled", false)

This only works in this case because :Destroy is the method of the instance GUI. The instances in the hierarchy are effectively one big metatable.

local x = {}
x.__index = x

function x.new(Name)
    local newX = setmetatable({}, x)
    newX.Name = Name

    return newX
end

function x:PrintName()
    print(self.Name)
end

local NewX = x.new("Bob")

NewX:PrintName() -- "Bob"
x.PrintName(NewX) -- "Bob"
-- Notice how these result in the same thing. This is what you're doing with GUI.Destroy

This is just part of object-oriented programming. .Enabled is a boolean and not a function so it doesn’t work the same.

thanks for the help, hopefully roblox adds support to enable/disable various instances using task.delay

1 Like

Honestly, I don’t really see a use for adding something like that. It’s usecase is for something very specific. And plus, doing:

task.delay(1, function()
    GUI.Enabled = false
end)

isn’t even that hard, nor is making a custom function.

Define your own property setter function.

local function SetProperty(Object, Property, Value)
	Object[Property] = Value
end

task.delay(1, SetProperty, ScreenGui, Enabled, false)
1 Like