Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make a Dropper that expires?

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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 

0
how would i add that to my script now ? ( IM A NOOB at scripting) TheeeDiamond 0 — 6y
0
Edited mattscy 3725 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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

Answer this question