Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Cannot Resume Dead Coroutine But Unsure How To Fix?

so i tried working with a coroutine and i am calling it multiple times per second which i know is the issue but i am not sure how to fix it and this is vital to my game because as the script clearly says i am trying to delete the parts after 10 seconds but it is part of the game to call this function multiple times with short intervals, if someone could help me with this it would be great

Script:

local Event = game.ReplicatedStorage.Break
local Debounce = false

local Timer = coroutine.wrap(function(part)
	wait(10)
	part:Destroy()
end)

Event.OnServerEvent:Connect(function(Player,hit)
--	print(hit,hit:GetFullName())
	if hit.Parent == workspace and hit.Name == "DestPart" then
		if Debounce == false then
			Debounce = true
			hit.Anchored = false
			Timer(hit)
	--		wait(10)
	--		hit:Destroy()
			Debounce = false
		end
	elseif hit.Parent:IsA("Model") and hit.Name == "DestPart" then
		if Debounce == false then
			Debounce = true
			for i, v in pairs(hit.Parent:GetDescendants()) do
				if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
					v.Anchored = false
					Timer(v)
	--				local ex = Instance.new("Explosion")
	--				ex.Parent = v
	--				ex.Position = v.Position
	--				ex.Visible = false
	--				ex.BlastPressure = 50
	--				ex.DestroyJointRadiusPercent = 0
	--				ex.ExplosionType = "NoCraters"
	--				wait(10)
	--				v:Destroy()
				end
			end
			Debounce = false
		end
	end
end)

1 answer

✓ Accepted answer

You’ll have to create/wrap a new coroutine each time since once a coroutine has ran, it can’t be restarted, it is dead.

local function Timer(part)
    coroutine.wrap(function()
        part:Destroy()
    end)()
end

1 comment

0

sweet thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.