My hit detection for the beam is acting weird

Hi, For some reason, for my hit detection, (which is good for other types of attacks) seem to be bugged if you try using it for a beam type attack, the attack is supposed to damage the enemy continously and can hit multiple people, but for this, im not even aiming at them and they get hit ONCE for some reason? I checked the hitbox and its going the right way.
this is the hit detection, im pretty sure something is wrong here (I use region3)

-- dont worry abt exploiters i added security measures on the serveerside
-- beam is the part
game.ReplicatedStorage.ExtraDMG:WaitForChild("BeamDMGgku").OnClientEvent:Connect(function(beam,whichway,dmg,duration,stunduration,soundid,soundvolume,knockrange, Particle)
	local chr = plr.Character
	if chr:FindFirstChild("DamagePart") then return end
	local Region = Region3.new(beam.Position - (beam.Size/2),beam.Position + (beam.Size/2)) 
	for i,hit in pairs(workspace:FindPartsInRegion3(Region,nil,math.huge)) do 
		if hit.Parent:FindFirstChild("Humanoid") then
			if hit.Parent.Name ~= plr.Name then
				game.ReplicatedStorage.DamageStuff.ServerDamage2:FireServer(chr,dmg, whichway, duration,stunduration,soundid, soundvolume,knockrange,hit,Particle)
			end
		end
	end
end)

It seems to be working perfectly with Touched, but the problem with that is that Touched lags my pc to oblivion. I also tried to use raycast, it seems to be accurate, but it only hits once and one person gets hit. any help would be appreciated!

Well there’s your problem, the issue is region 3 cannot be rotated because region 3 is axis-aligned.

Use the new spatial query API instead: GetPartBoundsInBox

Make sure the visualization is correct,

Ah yes, I checked it and the hitbox is going the same way as the beam + has the same size, I will try getpartsboundinbox maybe

the problem is, GetPartsBoundInBox() always prints nil. I don’t know why this happens.

local params = OverlapParams.new(list,Enum.RaycastFilterType.Whitelist,20,'Default')
	local objectsInSpace = workspace:GetPartBoundsInBox(beam.CFrame,beam.Size,params)
	print(objectsInSpace.Name) -- prints nil everytime
	if objectsInSpace.Parent:FindFirstChild("Humanoid") then
		print("onkec") -- does not run
		if objectsInSpace.Parent:FindFirstChild("Humanoid") then
			if objectsInSpace.Parent.Name ~= plr.Name then
				game.ReplicatedStorage.DamageStuff.ServerDamage2:FireServer(chr,dmg, whichway, duration,stunduration,soundid, soundvolume,knockrange,hit,Particle)
			end
		end
	end

GetPartBoundsInBox → “Returns an array of parts whose bounding boxes overlap a given box.”

So, your issue is that “objectsInSpace” is actually a table that houses all parts that overlap with the CFrame and Size you inputted.

You have to loop through the table:

for _, part in ipairs(objectsInSpace) do
      -- check for humanoid
end

And to make sure you do not damage the same humanoid twice, make sure to cache the humanoid results for every time the attack is made:

local damagedHumanoids = { }
for _, part in ipairs(objectsInSpace) do
      -- fetch humanoid
      local humanoid = -- blah blah

      -- the humanoid has already been damaged so continue to next iteration
      if table.find(damagedHumanoids, humanoid) then continue end  
     
      table.insert(damagedHumanoids, humanoid)

      -- deal damage
end

-- then we clear the damagedHumanoids table to prevent memory leaks of dead objects!
table.clear(damagedHumanoids)

Another thing, IIRC, overlapparams does not let you set parameters in its “new”(Constructor) method.
You will have to set the parameters after you construct it like so:

local params = OverlapParams.new()
params.FilterDescendantsInstances = list
params.FilterType = -- and so on

Hopefully this helps!

I see… Thanks for the help but still, this doesnt seem to print. I quite dont understand this, so please tell me what’s wrong with it (my first time with GetPartBoundsInBox)

	local list = {}
	
	for i,v in pairs(workspace:GetDescendants()) do
		if not v.Parent:FindFirstChild("Humanoid") then
			table.insert(list,v)
		end
	end
	
	table.insert(list,chr)
	local params = OverlapParams.new()
	params.FilterDescendantsInstances = {list}
	params.FilterType = Enum.RaycastFilterType.Blacklist
	local objectsInSpace = workspace:GetPartBoundsInBox(beam.CFrame,beam.Size,params)
	print('thisra') -- this prints though
	local damagedHumanoids = {}
	for _, part in ipairs(objectsInSpace) do
		print(part.Name) --Does not print...
		if part.Parent:FindFirstChild("Humanoid") then
			print('humand')
			local humanoid = part.Parent.Humanoid
			if table.find(damagedHumanoids, humanoid) then continue end  
			table.insert(damagedHumanoids, humanoid)
			if part.Parent.Name ~= plr.Name then
		
				game.ReplicatedStorage.DamageStuff.ServerDamage2:FireServer(chr,dmg, whichway, duration,stunduration,soundid, soundvolume,knockrange,part,Particle)
			end
			table.clear(damagedHumanoids)
		end
	end
end)

Is it bc something wrong with the beam? I see the hitbox (part) moves the intended way on the beam though (It extends on RightVector)

this a rlly inefficient way of doing it but, i made a beam hitbox once and my solution was to use GetTouchingParts() to get an array of every part inside that part. the caveat to it is that it only works on cancollide objects so you have to set a parts cancollide on, run the GetTouchingParts() method, then turn the parts cancollide false, and you get every single part in the beam.