Problems with Region3

Problem:

My region is supposed to damage a humanoid by 6 when it detects it, but currently the region3 is detecting a Character’s each individual body parts and is damaging by 6 according to the body parts that im standing next to/ in the region’s box. https://streamable.com/5xu3gf

As you see in the video i stand next to one of the character’s arm and it hit damages the character by 6 but when i stand in front of it it damages the character 7 times since im standing in front of all 7 of the characters body parts.

What im trying to achieve:

I want it so the region can only detect an entire character instead of each individual parts.

Script:

local Size = Vector3.new(5, 6, 5.8);
local pos = Character:WaitForChild("HumanoidRootPart").CFrame*CFrame.new(0,0,-Size.Z/2).p;
local Region = Region3.new(pos - (0.5 * Size), pos + (0.5 * Size));
	local RTable = workspace:FindPartsInRegion3(Region, nil ,20)
	for i,v in pairs(RTable) do print(v)
		if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= Character then	
			if Combo == 1 or Combo == 2 or Combo == 3 or Combo == 4 then
					v.Parent.Humanoid:TakeDamage(Damage)
							sound1:Play()
				        
				
				
				
			end
	end				
end
	```

This is a script I use for my splashes. It might not be 100% optimised (not sure if it causes any data leaks because the table isn’t cleaned after use), but is surely does the job!

    local SPLASH_RADIUS = Vector3.new(10,10,10)
	local IMPACT_DAMAGE = 50
	local splashed = {}		
	local splashPart = script.Parent
		
	local partsInRange = game.Workspace:FindPartsInRegion3(Region3.new(splashPart .Position - SPLASH_RADIUS, splashPart .Position + SPLASH_RADIUS), nil, 500)		
	for _,v in pairs(partsInRange) do
		local taggedHum = v.Parent:FindFirstChild("Humanoid")
		if taggedHum and not splashed[taggedHum] then
			splashed[taggedHum] = true
			table.insert(splashed, taggedHum)
		end
	end
	for _,v in ipairs(splashed) do
		v:TakeDamage(IMPACT_DAMAGE)
	end

It basically goes over all parts within this radius and checks for each of them if their ‘tag’ (the human) has been added to the splashed table. If let’s say 4 / 10 parts of the same character are in range, it has already added this character/human to the table and won’t do so again.
It will however, since another character might not be added yet, add them too!

After that, the script loops through this array (all values inside a table, I believe) and damages each of these values.
Note: since only the humans (e.g. 4) are added to this table, only they will receive, in this case, damage.
You might have to format the script to your likings or simply copy/use some lines of it.

2 Likes

I believe so, yes.
This page on Region3 might be interesting.

It tells you FindPartsInRegion3 uses 3 parameters being: The region, an instance to be ignores and the maximum amount of parts it checks.

In my script, that would be:

game.Workspace:FindPartsInRegion3(Region3.new(splashPart .Position - SPLASH_RADIUS, splashPart .Position + SPLASH_RADIUS), nil, 500)

Where;

  • the first ‘stuff’ in brackets is the region,
  • the second, being nil is the instance that’s being ignored ← I believe this is what you mean
    it can only ignore one instance! So no tables
  • the third and last is the maximum amount of parts in that region being checked. 500 is quite a lot for this small 10x10x10 region, haha.

There’s also indeed ways to ONLY check certain parts and one to ONLY ignore certain ones (being more than just that one instance I mentioned in my list)

In order to do this, you can use a variant such as:FindPartsInRegion3WithIgnoreList and :FindPartsInRegion3WithWhiteList. These work relatively the same, except that they allow you to add a list (an array) of objects to ignore or whitelist!

Might want to experiment with that! :grinning:

1 Like

Fixed : I didn’t break the loop after damaging the humanoid which is why it dealt so much damage.

1 Like