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)
p: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)
end
while true do
wait(2)
fire()
end
Also, I suggest you to read the article about Debris
2 comments
how would i add that to my script now ? ( IM A NOOB at scripting)
Edited