How can i affect multiple enemies with a single attack?

hi! im making area of effect (aoe) item things i want to make it takes some damages and burn damage

but script only does work on one enemy i dont know how to fix this

script.Parent.Remote1.OnServerEvent:Connect(function(plr)
	local Animation = script.Parent.LmbAnimation1
	local Animationtrack = script.Parent.Parent:FindFirstChildWhichIsA("Humanoid"):LoadAnimation(Animation)
	Animationtrack:Play()
	task.wait(1)
	local sound = script.Parent.Sound
	sound:Play()
	
	local part = Instance.new("Part", workspace)
	part.Shape = Enum.PartType.Ball
	part.Size = Vector3.new(5,5,5)
	part.BrickColor = BrickColor.new("Neon orange")
	part.CanCollide = false
	part.Anchored = true
	part.Material = Enum.Material.Neon
	part.CFrame = script.Parent.Parent:FindFirstChild("HumanoidRootPart").CFrame * CFrame.new(0,-3,-5)
	
	local tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Circular, Enum.EasingDirection.Out, 0, false, 0)
	local goal = {}
	goal.Size = part.Size + Vector3.new(10,10,10)
	goal.Transparency = part.Transparency + 1
	local ts = game:GetService("TweenService")
	local tween = ts:Create(part, tweeninfo, goal)
	tween:Play()
	
	local char = plr.Character
	local rootpart = char:WaitForChild("HumanoidRootPart")
	for i, v in pairs(game.Workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") and v ~= char then
			local vhum = v:FindFirstChild("Humanoid")
			local vrootpart = v:FindFirstChild("HumanoidRootPart")
			
			if (part.Position - vrootpart.Position).Magnitude <= 5 then
				vhum:takeDamage(40)
				local firemodule = require(game.ServerScriptService.FireModuleScript)
				local head = v:FindFirstChild("Head")
				local facecenterattachment = head:FindFirstChild("FaceCenterAttachment")
				firemodule:burn(20, facecenterattachment)
			end
		end
	end
	game.Debris:AddItem(part, 1.1)
end)

how to run on multiple enemies?

2 Likes

I don’t think this is the best way to create a hitbox,
Try using .Touched or Raycast Hitbox by TeamSwordphin.

1 Like

This doesn’t answer their question

I think making better hitboxes will fix this problem.

Sorry if I am wrong.

This is most likely messing up due to how you’re handling finding players to damage. Instead of messing with player magnitude, use a .Touched event on the orange part. You can make the orange part damage multiple enemies by assigning damage, then adding them to a table so that they won’t get damaged again if they’re in the table. Here’s a quick function I wrote up for this:

local hit = {} --damage table (add the local player here if you don't want yourself to be damaged)

explosionPart.Touched:Connect(function(touch)
	if touch.Parent:FindFirstChildOfClass("Humanoid") and not hit[touch.Parent] then --check if touch is a humanoid & not already in table
		if touch.Parent:FindFirstChild("Humanoid").Health > 0 then --humanoid is alive
			hit[touch.Parent] = true --add to table
			touch.Parent:FindFirstChild("Humanoid").Health -= 25 --damage humanoid
			task.wait(0.5) --cooldown
			hit[touch.Parent] = nil --remove from table
		end
	end
end)
1 Like

thanks for writing script ill try it when i get home

there is new issue
it certainly worked but it also hurt item owner
how do i fix that?

nvm i just have to hit.parent ~= plr.char

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.