If one can just do this:

delay(3, function()
	if projectile and projectile.Parent then
		projectile:Destroy()
	end
end)

Why is there Debris, if the above code is just equivalent to:

Debris = game:GetService("Debris")
Debris:AddItem(Part, 3)

Is it because since Debris is written in native code it can run it on the C++ side and be faster than Lua? Why does this exist?

3 comments

0

It adds an item to the game for a certain amount of time. So, it'll exist for 3 seconds and then disappear. So, you don't have to make it disappear yourself.

0

It's just a more effective way without delaying the rest of your code.

0

delay() spawns a new thread, so it doesn't delay the rest of the code, so the two blocks of code act identically.