I’m working on some code that does effects and cleans up debris, and I have some issues with the function not receiving a complete table of everything that’s been hit. Do you have any ideas for a more consistent method? It currently makes a table of all the parts, then runs a function to address all of them.
fragExplosion.Hit:Connect(function(part, dist)
--print(part)
if not part.Anchored then
if part.Parent:FindFirstChild("Humanoid") or part.Name == "HumanoidRootPart" then
ExplosionHitHuman(part.Parent, fragDamage, dist, tag, position, device)
else
if part:GetAttribute("HP") then
local hp = part:GetAttribute("HP")
hp -= fragDamage / (dist*0.4)
end
--purpose of this???
--if fragExplosion.DestroyJointRadiusPercent <= 0 then return end
if debugMode then
part.BrickColor = BrickColor.new(0,0,255)
end
--not using tables anymore, since we're gonna trigger the function every single time a part is hit
table.insert(partsAffected, part)
if dist <= fragExplosion.BlastRadius * fragExplosion.DestroyJointRadiusPercent then
--weld broken
if debugMode then
part.BrickColor = BrickColor.new(255,0,0)
end
local weld = part:FindFirstChildWhichIsA("WeldConstraint") or part:FindFirstChildWhichIsA('Weld')
if weld and weld.Enabled then
local otherpart
if weld.Part0 ~= part then
otherpart = weld.Part0
else
otherpart = weld.Part1
end
if otherpart:FindFirstChildWhichIsA("WeldConstraint") or otherpart:FindFirstChildWhichIsA("Weld") then
DebrisService:AddItem(otherpart, 12 + math.random(1,1000)/100)
if debugMode then
otherpart.BrickColor = BrickColor.Green()
end
end
weld:Destroy()
else
part:Destroy()
end
debrisParticlesEvent:FireAllClients("DebrisSmoke", part)
debrisParticlesEvent:FireAllClients("DebrisFlying", part)
if dist <= fragExplosion.BlastRadius * fragExplosion.DestroyJointRadiusPercent * 0.5 then
--obliteration radius
transparencyEvent:FireAllClients(part, 0, 1, true)
wait(1)
part:Destroy()
else
DebrisService:AddItem(part, 12+math.random(1,1000)/100)
end
end
end
end
end)
end
if device then
DebrisService:AddItem(device, 10)
end
wait(4)
CheckForDebrisToDelete(partsAffected)
end