Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a Dropper that expires?

Ive been trying to make a dropper that the blocks expire after awhile

function fire()
        local p = Instance.new("Part")
        p.Position = script.Parent.Position
        p.Size = Vector3.new(1,1,1)
        p.BrickColor = BrickColor.new(26)
        p.BottomSurface = 0
        p.TopSurface = 0
        p.Name = "TycoonBrick"
        p.Parent = script.Parent

end 


while true do 
     wait(2)
     fire()

end 

2 answers

When creating the dropped blocks, add them to Debris to be deleted after a set amount of time.

function fire()
        local p = Instance.new("Part")
        p.Position = script.Parent.Position
        p.Size = Vector3.new(1,1,1)
        p.BrickColor = BrickColor.new(26)
        p.BottomSurface = 0
        p.TopSurface = 0
        p.Name = "TycoonBrick"
        p.Parent = script.Parent
	game:GetService("Debris"):AddItem(p,5) -- will delete after 5 seconds
end 


while true do 
     wait(2)
     fire()

end 

2 comments

0

how would i add that to my script now ? ( IM A NOOB at scripting)

0

Edited

You should try using the wait() function to wait until we want to remove the part (like you did with the cooldown) and then use Destroy() to get rid of the part.

Try this:

function fire()
        local p = Instance.new("Part")
        p.Position = script.Parent.Position
        p.Size = Vector3.new(1,1,1)
        p.BrickColor = BrickColor.new(26)
        p.BottomSurface = 0
        p.TopSurface = 0
        p.Name = "TycoonBrick"
        p.Parent = script.Parent
	wait(5) --replace 5 with the wait time
	p:Destroy() --call Destroy()
end 


while true do 
     wait(2)
     fire()

end 

Alternatively, you can try to use the Debris method like mattscy did.

function fire()
        local p = Instance.new("Part")
        p.Position = script.Parent.Position
        p.Size = Vector3.new(1,1,1)
        p.BrickColor = BrickColor.new(26)
        p.BottomSurface = 0
        p.TopSurface = 0
        p.Name = "TycoonBrick"
        p.Parent = script.Parent
	game:GetService("Debris"):AddItem(p,5) --replace 5 with wait time
end 


while true do 
     wait(2)
     fire()

end 

Also, I suggest you to read the article about Debris

This discussion is preserved as it was. New answers, comments, and votes are closed.