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.
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)
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)
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.