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

How do I make a brick disappear after it has existed for 10 seconds?

Asked by 9 years ago

I'm trying to make a tycoon, but the bricks keep piling on the sides eventually causing lag, I want any brick created by this script to be deleted/destroyed after existing for 10 seconds.

script.Parent.ClickDetector.MouseClick:connect(function()
    local x = Instance.new("Part")
    x.BrickColor = BrickColor.new("Institutional White")
    x.Position = Vector3.new(-163, 4.7, 216.7)
    x.Size = Vector3.new(1,1,1)
    x.Parent = script.Parent.Parent
    x.Name = "TycoonBrick"
end)

But I'm not sure how to do that.

3 answers

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
9 years ago
script.Parent.ClickDetector.MouseClick:connect(function()
    local x = Instance.new("Part")
    x.BrickColor = BrickColor.new("Institutional White")
    x.Position = Vector3.new(-163, 4.7, 216.7)
    x.Size = Vector3.new(1,1,1)
    x.Parent = script.Parent.Parent
    x.Name = "TycoonBrick"
    game:GetService("Debris"):AddItem(x, 10) --"x" is the object you're putting in Debris, in this case the TycoonBrick. "10" is the amount of time the object stays in the game before it is removed, in this case 10.
end)
Ad
Log in to vote
1
Answered by
Relatch 550 Moderation Voter
9 years ago
script.Parent.ClickDetector.MouseClick:connect(function()
    local x = Instance.new("Part")
    x.BrickColor = BrickColor.new("Institutional White")
    x.Position = Vector3.new(-163, 4.7, 216.7)
    x.Size = Vector3.new(1,1,1)
    x.Parent = script.Parent.Parent
    x.Name = "TycoonBrick"
    wait(10)
    x:Destroy()
end)
Log in to vote
0
Answered by 9 years ago
local brick ("TycoonBrick")
wait(10)
Destroy()
end

That is my guess. Sorry If it doesn't work I am not a very good scripter but I have my moments.

Answer this question