Having Trouble with Region3 Hit Effect w/ Run Service

The script is working just how I planned it to, but there are too many unnecessary outputs, I’m assuming it’s because of the RunService. The errors print that some of the projectiles have already been destroyed. But it eventually stops after the function is disconnected!

Here’s the problem. I tried to add sort of a damage debounce so it won’t constantly run the output every millisecond until the function is disconnected, but it seems even if I edit this script just a little bit, the function breaks and it won’t perform the Hit Effect, but only the damage. I will provide below some pictures of the “errors” that print as a result and the unnecessary outputs I am trying to get rid of.

NON EDITED SCRIPT:
fdd5760485222ee60b8b03a285fbf0bd
(Errors but hit effect)

EDITED SCRIPT:

7a8fac021962a57e2bbce349bf66288d

(No Errors but not Hit Effect)

I’ve tried to add the debounce like I’ve stated above but then the script breaks and there is no hit effect, only the damage. also I’m using Region3 because I hate the touched event, it provides less latency for me.

local Touched
	
	local function onHeartBeat()

		local pos1 = Projectile.Position - (Projectile.Size / 2)
		local pos2 = Projectile.Position + (Projectile.Size / 2)

		local Region = Region3.new(pos1, pos2)



		local partsInRegion = workspace:FindPartsInRegion3(Region, Projectile, 100)

		for _,v in pairs(partsInRegion) do
			if v.Parent:FindFirstChild('Humanoid') ~= nil then
				v.Parent:FindFirstChild("Humanoid"):TakeDamage(1)
				Touched:Disconnect()
				
			else if v:IsA("Part") or v:IsA("MeshPart") and v.Parent:FindFirstChild('Humanoid') == nil then
					local HitParticle = Projectile:FindFirstChild('Hit')
					Projectile.Fire.Flame:Destroy()
					Projectile.Fire.Sparks:Destroy()
					Projectile.Fire.PointLight:Destroy()
					HitParticle:Emit(100)
					wait(.5)
					Projectile:Destroy()
					Touched:Disconnect()
					
				end
			end
		end	
	end

	
	Touched = RunService.Heartbeat:Connect(onHeartBeat)
	
	
	
	
	
	
	
	
	
end

Any help is greatly appreciated! Thanks for your time!

1 Like

Nevermind figured it out. Thanks for the help!