Trying hit multiple targets

You can write your topic however you want, but you need to answer these questions:

  1. I tried make hitboxes what can hit multiple targets but it works bad

anybody know how i can make hitbox hit multiple targets once/many times

local hitbox = {}
hitbox.attack = function(size,cframe,root,dmg,howlong,effect,CanSound,plr)
		local targets = {}
		local bb = 0
		local ht = Instance.new("Part")
		ht.Size = size
		ht.Name = "Hitbox"
		ht.CanCollide = false
		ht.Transparency = 0.9
		ht.Material = Enum.Material.SmoothPlastic
		ht.Color = Color3.fromRGB(0,255,0)
		local weld = Instance.new("Weld")
		ht.CFrame = cframe
		ht.Massless = true
		weld.Part0 = ht
		weld.Part1 = root
		weld.C0 = ht.CFrame:Inverse()
		weld.C1 = root.CFrame:Inverse()
		ht.Parent = workspace
		weld.Parent = ht
		game.Debris:AddItem(ht,howlong)
		ht.Touched:Connect(function(hit)
		if hit and hit.Parent:FindFirstChild("Humanoid") ~= nil and hit.Parent.Name ~= plr.Name then
			local item = table.find(targets,hit.Parent)
				if item == nil then
					bb = bb+1
					table.insert(targets,bb,hit.Parent)
					local enemy = hit.Parent.Humanoid
					enemy:TakeDamage(dmg)
				end
			end
		end)
	end
return hitbox
2 Likes

How about you just use a region three or get GetTouchingParts()

can you bring me example? it would be cool

Well just search up region three or gettouchingparts() in the search and youll find some good information

You could put every target that was hit into a table and check if they were in the list

local alreadyHit = {}
function addHit(target)
 if not alreadyHit[target.Name] then --checks if target is in the table
  alreadyHit[target.Name] = true --stores target to table for future check

  --do stuff here

  delay(.1,function() alreadyHit[target.Name] = nil end) --deletes target from the table
 end
end)
2 Likes

its good idea, but are you sure you wrote it right?

My mistake, I’ve made a typo. I’ve updated the code now.

its still cant attack many targets

idk if u have already found a solution but this should do it

Attacked = {}

if not Attacked[table.find(Attacked,Target)] then
table.insert(Attacked,Target)
--stuff 
for i =1 , #Attacked do
	if Attacked[i] == Target then
		table.remove(Attacked,i)
	  end
    end
end
3 Likes

Unrelated to the scripting, but you have some z-fighting going on there on the stand and on your clothes - just thought you might want to fix that.