Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED] How to make an area of effect damage system?

I'm trying to make a big blast that my user can create. This blast is supposed to damage everything it touches, but it only damages one player/NPC. I know this is because of how I have the debounce set up, but how would I do it differently to work as an AoE move?

Script:

-- Damage
for i,v in pairs(game.Workspace:GetChildren()) do
	if v == t1 or v == t2 or v == t3 or v == t4 or v == t5 or v == t6 then
		
		local db = false
		
		v.Touched:Connect(function(hit)
			if not db and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= player.Name then
				
				db = true
				tagged(hit,player)
				
				local hum = hit.Parent.Humanoid
				hum:TakeDamage((powerLevel.Value*3)+math.random(40,50))
				
				wait(10)
				db = false
				
			end
		end)
		
	end
end

Any help is appreciated!

3 comments

0

use explosion and explosion.hit, its the easiest only known way

0

no

0

This is a custom-made explosion using mesh parts. I don't think explosion.hit is what I'm looking for.

1 answer

✓ Accepted answer

u can make a ignore list for all the players hit, like this:

place script in part u want ppl to take damage from:

local part = script.Parent
local ignoreList = {}

part.Touched:Connect(function(hit)
	local char = hit.Parent
		
	local isIgnored = false
	
	for i, ignored in pairs(ignoreList) do
		if ignored == char then
			isIgnored = true
		end
	end
	
	if isIgnored == false then
		table.insert(ignoreList, char)
		
		char:FindFirstChild("Humanoid"):TakeDamage(10)
		
		wait(1)
		
		for i, ignored in pairs(ignoreList) do
			if ignored == char then
				table.remove(ignoreList, i)
			end
		end
	end
end)

6 comments

0

*disclaimer i never tested it on multiple ppl

0

also i realized the touch event only detects the player when its character is in motion. this can be solved using the rotated region3 thing but im sleepy so i wont do that edit.

0

instead of an table, local ignoreList should only be the user or the party member (if you had that thingy),

0

I don't think the player will have to be moving for my script, since the explosion is growing in size, moving instead of the player, but thanks! I'll try this.

0

Aha! There! It worked perfectly on my end. Thanks for the help, I'll accept your answer now.

0

ah ok

This discussion is preserved as it was. New answers, comments, and votes are closed.