AOE Damage Help

I am making an attack that does AOE damage, the issue I am having is that I am using a Region3 which results in the code running way more than it should be.

Here is my code:

		local TempCheckHitbox = Region3.new(TempCheckVFX.Position - (TempCheckVFX.Size / 2), TempCheckVFX.Position + (TempCheckVFX.Size / 2))
		local piREGION = workspace:FindPartsInRegion3(TempCheckHitbox, char, 1000)
		
		local AOEDamage = coroutine.wrap(function()
			task.delay(2,function()
				for i, v in pairs(TempCheckVFX:GetDescendants()) do
					if (v:IsA('ParticleEmitter')) then
						v.Enabled = false
					end
				end
				
				coroutine.yield()
			end)
			
			for i = 1,15 do
				task.wait(0.1)
				for i,v in ipairs(piREGION) do
					local model = v:FindFirstAncestorOfClass('Model')

					if model then
						local hum = model:FindFirstChildOfClass('Humanoid')
						
						print('ow')
						hum:TakeDamage(0.5)
					end
				end
			end
		end)
		AOEDamage()

It runs 10 times each so it results in 52.5 damage instead of 7.5. The line of code I’m mainly having a problem with, is where it actually finds all the parts in the region.

If you guys have a better alternative or a fix for this, please tell!

Add a debounce———————————————————

How would it look, that’s what I thought originally but I don’t know how to implement it.

Have a table. When it detects a char, add the pls.name as a key in the table and set it to a value. Before damaging check if tab[plr.Name] == nil. Have a corutine warp function which waits for x amount of time and then sets tab[pl.Name] == nil

2 Likes

Sorry, but I have no idea how I’m supposed to imagine that. I get the idea you’re going for, but it’s going to take some thinking to make sure it doesn’t add a duplicate char to the table.

Just make sure it doesn’t damage the player twice, You can do this by making a table

local PlayerHit = {}

if PlayerHit[Player -- Player being the person who got hit] == false or PlayerHit[Player] == nil  then  
PlayerHit[Player] = true 
hum:TakeDamage(0.5)
end

-- You can then reset the PlayerHit by just making the table empty
PlayerHit = {}
1 Like
		local TempCheckHitbox = Region3.new(TempCheckVFX.Position - (TempCheckVFX.Size / 2), TempCheckVFX.Position + (TempCheckVFX.Size / 2))
		local piREGION = workspace:FindPartsInRegion3(TempCheckHitbox, char, 1000)
		
		local AOEDamage = coroutine.wrap(function()
			local PlayerHit = {}
			
			task.delay(2,function()
				for i, v in pairs(TempCheckVFX:GetDescendants()) do
					if (v:IsA('ParticleEmitter')) then
						v.Enabled = false
					end
				end
				
				PlayerHit = {}
				coroutine.yield()
			end)
			
			for i = 1,15 do
				task.wait(0.1)
				for i,v in ipairs(piREGION) do
					local model = v:FindFirstAncestorOfClass('Model')

					if model and PlayerHit[model] == false or PlayerHit[model] == nil then
						local hum = model:FindFirstChildOfClass('Humanoid')
						PlayerHit[model] = true
						
						print('ow')
						hum:TakeDamage(0.5)
					end
				end
			end
		end)
		AOEDamage()

I have this code so far, still having trouble. Still confused lol, sorry for the trouble

I am typing this on tablet so sorry if I make spelling mistakes.

local tab = {}— debounce tab

If tab[plr.name]==nil then —check if nil
tab[plr.name] = 1 — set to any value other than nil. Make it not nil so it does not pass through the ifstatement again

corutine.wrap(function()
task.wait(0.1)—wait time
Tab[plr.name]= nil—now set to nil so it can run again
end)()
end
1 Like

So in my code, would it be model.Name?

Got the code working, thank you.

I suggest checking if the model is a player.

local plr = game.players:get player from character (hit.Parent)

If plr then
—Add the debounce and the code in the previous post
end

I want it to work on dummies as well

Oh then do what you were using before. You can ask questions about the code

Yeah, the name of the dummy or character model

Typically you’d want to do the following.

local PlayerDebounces = {[Player1] = true, [Player2] == true}

While you can use any “truthy” (anything which isn’t nil or false) value in place of true, true is the most intuitive and makes the code more readable.