I'm making a game and in the map I need to block that will open like 5 minutes after the game had started, and I've looked up tutorials and other things, but nothing has worked. Please help.
Is there a way to make a block disappear after a certain amount of time?
1 answer
To make an Instance disappear after a given period, it is of best practice to apply DerbisService to your Script. Using the AddItem function of said Service allows the user to schedule a removal of an Object after a provided window. AddItem is also ran on a separate thread, meaning it will not interrupt your program and yield the Script; it will also ensure your program does not raise an exception if the Instance is unexpectedly null.
local DerbisService = game:GetService("Derbis")
local Part = workspace.Part
DerbisService:AddItem(Part, 60*5) --// Five minute window before removal
A simpler approach:
game.Derbis:AddItem(workspace.Part, 60*5)
This function is equivalent to Instance:Destroy(), meaning the Object will be permanently removed unless the Instance of reference is a clone and can be replaced upon re-loading said map. Otherwise, it is suggested you set the Parent of an Object to nil if you wish to remove it and reuse it again. You can use the delay function to gain the same effect as AddItem if you wish to do this and still run uninterrupted code
local Part = workspace.Part
delay(60*5, function()
Part.Parent = nil
end)
--// Set the Parent back to workspace when needed
This discussion is preserved as it was. New answers, comments, and votes are closed.
