Hi, i’m making a time stop ability where everything, projectiles, player, particles, parts, etc freeze. But projectiles and everything else that uses Debris Service or gets destroyed after a certain wait still get deleted. I was wondering if it was possible to temporarily stop/delay the projectiles/items from deleting while the time stop is active.
I’d make a custom Debris Service in that case, the basic idea would be like this
Debris = {
queue = {}
}
function Debris:Pause()
if this.PauseStart != nil then
error("Already paused")
end
this.PauseStart = os.clock()
end
function Debris:Resume()
if this.PauseStart == nil then
error("Not paused")
end
-- this increases how long everything will sit before being deleted
for each item in queue
add (os.clock() - this.PauseStart)
-- this unpauses
this.PauseStart = nil
end
function Debris:AddItem(instance, lifetime)
add instance to queue with the time (os.clock() + lifetime)
-- the item will be deleted at or after that saved time
end
setup a function connected to RunService.Stepped to trigger each step
if this.PauseStart is not nil
return
else
destroy all instances in queue that have a time > os.clock()
end
end
this is pseudocode that I haven’t tried making, so it’ll probably be a bit different if you implement it
As far as I know there isn’t a way to cancel the pending deletion of a part inside the Debris service. You will have to implement your own method of managing parts
This is just an example of how you can make your own “Debris service”
local queue: {[Part]: boolean} = {}
local queueDeletion: (Part, number) -> (boolean) = function(p, lifetime)
assert(type(lifetime) == 'number')
if p and p.Parent ~= nil then
task.spawn(function()
queue[p] = true
task.wait(lifetime)
if p and p.Parent ~= nil and queue[p] then
p:Destroy()
queue[p] = nil
end
end)
return true
end
return false
end
local cancelDeletion: (Part) -> (boolean) = function(p)
if p and p.Parent ~= nil and queue[p] then
queue[p] = nil
return true
end
return false
end
--example usage
queueDeletion(workspace:WaitForChild('1'), 5)
queueDeletion(workspace:WaitForChild('2'), 5)
task.wait(2)
cancelDeletion(workspace:WaitForChild('1'))