Help with decay script

So I am making a game called spleef and I want to make a script that ‘decays’ the blocks(deletes them).

The problem is that they only decay 1 at a time.

I tried using spawn() but it hasn’t been working.

How can I make it happen at the same time?

Also my internet has been acting weird so if I dont respond thats why.

We cannot help you if you don’t give us any material to work with. There are 1000 ways to implement this so we can’t do anything without some code.

Sorry I forgot:

local DecayObject = {}
DecayObject.__index = DecayObject

function DecayObject.new(object)
	local self = {}
	self.Object = object
	self.Decaying = false
	self.DecayTime = nil
	
	setmetatable(self, DecayObject)
	return self
end

function DecayObject:Configure(DecayTime)
	self.DecayTime = DecayTime
end

function DecayObject:Enable()
	self.Decaying = true
	print("Decaying")
	self.Object.BrickColor = BrickColor.new("Medium blue")
	self.Object.Transparency = 0.5
	wait(self.DecayTime)
	self.Object:Destroy()
end

return DecayObject

The easiesy fix would be:

local serviceDebris = game:GetService("Debris")

...

serviceDebris:AddItem(self.Object,self.DecayTime)

The simplest way to do this would probably be to name them the same name and to use the destroy function on them or just make can collide to off and transparency to 1.

you could enclose the whole enable method in a coroutina

function DecayObject:Enable()
    coroutine.warp(function () 
        self.Decaying = true
        print("Decaying")
        self.Object.BrickColor = BrickColor.new("Medium blue")
        self.Object.Transparency = 0.5
        wait(self.DecayTime)
        self.Object:Destroy()
   )() 
end

then you should call the enable method of all your objects at the same time. something like this

for _, object in pairs(decayObjects) do
    object:Enable()
end

Thank you, I wanted to give the solution long ago but my internet stopped working : (.

1 Like