Hey all. So I’ve wanted to avoid using Debris and instead use task.delay in a module due to its dated nature and potential problems which might arise from it and the like, thing is, however, it will stop as soon as the character is deleted (script inside requires the module). Would I be better off sticking with debris, trying another approach, or is there some sort of an oversight I made?
function Commonalities.DebrisClear(Instance, Time)
task.delay(Time, function()
Instance:Destroy()
end)
end
--Server Script requiring this below:
--[[task.spawn(function()
while task.wait(.33) and script.Parent:FindFirstChild("Humanoid").Health > 0 do if
script.Parent:FindFirstChild("Humanoid").FloorMaterial ~= Enum.Material.Air then local DamageTrail = game:GetService("ServerStorage").Assets.Trail:Clone()
DamageTrail.Touched:Connect(function(hit)
if require(game:GetService("ReplicatedStorage"):FindFirstChild("TeamRegistrations"))[game.Players:GetPlayerFromCharacter(script.Parent).Team.Name][game.Players:GetPlayerFromCharacter(hit.Parent).Team.Name] == nil then hit.Parent:FindFirstChild("Humanoid").Health -= 5
end end)
DamageTrail.CFrame = CFrame.new(script.Parent:FindFirstChild("HumanoidRootPart").CFrame.Position.X, script.Parent:FindFirstChild("HumanoidRootPart").CFrame.Position.Y - 2.501, script.Parent:FindFirstChild("HumanoidRootPart").CFrame.Position.Z)
DamageTrail.Parent = workspace--]]
require(game:GetService("ReplicatedStorage"):FindFirstChild("Functionalities")).DebrisClear(DamageTrail, 20)
end
end
end)