Function Problem

External Media

How do I make it so that this function only applies to the “ExplosionPart” the ShiningExplosion function spawns in? As of right now, when the function gets repeated, it only applies to the first ever “ExplosionPart” that the ShiningExplosion function spawned in, but I want it to only apply to new ExplosionParts. I’ve tried everything but I’m just lost tbh.

The script: ```lua
function OnRayHit(cast, raycastResult, segmentVelocity, cosmeticBulletObject)
– This function will be connected to the Caster’s “RayHit” event.
local hitPart = raycastResult.Instance
local hitPoint = raycastResult.Position
local normal = raycastResult.Normal
print(“It got triggered”)
if hitPart ~= nil and hitPart.Parent ~= nil then – Test if we hit something
local humanoid = hitPart.Parent:FindFirstChildOfClass(“Humanoid”) – Is there a humanoid?
if humanoid then
humanoid:TakeDamage(10)
end
coroutine.wrap(function()
ShiningExplosion(hitPoint, normal)
end)()

	local processedParts = {}

	coroutine.wrap(function()
		local WeldConstraint1 = game.Workspace.Terrain:FindFirstChild("ExplosionPart")
		if WeldConstraint1 and not processedParts[WeldConstraint1] then
			WeldConstraint1.WeldConstraint.Part1 = hitPart.Parent:FindFirstChild("HumanoidRootPart")
			if hitPart.Parent:FindFirstChild("HumanoidRootPart") == nil then
				WeldConstraint1.Anchored = true
			end

			processedParts[WeldConstraint1] = true
		print("It got triggered 2")
	end
	end)()
end

end