Region 3 issues

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

  1. **When I clone the blast to workspace I want the region 3 to act as a hit detector to deal dammage and ignore anything without a humanoid in it

  2. **it keeps returning nil

hb stands for hitbox inside the blast

here is the code chunk

	local region = Region3.new(hb.Position - (hb.Size/2),hb.Position + (hb.Size / 2))
	local hit = workspace:FindPartsInRegion3WithIgnoreList(region,{char},math.huge)
	if hit  then
		print("hit")
		print(hit.Name)
		local der = hit.Parent:findFirstChild("Humanoid")
	if der then
			hit.Parent:findFirstChild("Humanoid"):TakeDamage(17)
			else
		end
	end

You can also use RotatedRegion3:

I’ve used it and it doesn’t error/return nill

This is my first time using region 3 I figured I was just doing something wrong lol, ill try that though

I actually recommend RotatedRegion3
because it works with many more shapes than Region3

Line 2: The function can only return 20 parts
Line 2: What is char?
Lines 3-end: hit is going to be an array of BaseParts, so you will need to change the code

This function can only return 20 parts, so this method may not work if you have a lot of parts/players in an area.

char is the players character(…30chars)

That means the character and it’s descendants will be ignored which is not what you want.

Maybe you meant to use FindPartsInRegion3WithWhitelist.

I think it is what they wanted. This seems to be intended to ignore a specific player and damage everyone else.

@MainDirectory the points about it being an array and the default limit of 20 are the biggest things to work on first. I imagine this is reflected in errors in the output window about FindFirstChild not being an index of nil.

You should rename hit to hits on the second line, and replace if hit then with for _, hit in ipairs( hits ) do

I dont want it to dammage the characters humanoid thats making the blast only other players.

1 Like

I will attempt what your saying and get back to you, much thanks!

I had originally seen in a tut to put it as math.huge

As a slightly off topic piece of advice, I wouldn’t use regions for this, and instead I would simply do a magnitude check on all other players (and/or NPC’s) to determine if they are within a sphere radius (rather than a cube) of the point of interest, and do damage based on that.

It will be more performant if you use GetPlayers and have a CollectionService tag for your NPCs or keep them all in a specific folder, especially if what you’ve shown is inside of a loop or some RunService step connection.

I was considering magnitude, I really wanted to utilize raycast but its so thin its unreliable from what ive read and experienced

Rays absolutely would be unsuitable for this, I was more on about

for _, player in ipairs( game.Players:GetPlayers() ) do
    if player.Character and player.Character ~= char then
        local hrp = player.Character:FindFirstChild( 'HumanoidRootPart' )
        local hum = player.Character:FindFirstChild( 'Humanoid' )
        if hrp and hum then
            if ( hrp.Position - hb.Position ).Magnitude < hb.Size.X / 2 then
                hum:TakeDamage( 17 )
            end
        end
    end
end
2 Likes

i was gonna go about it in a way that you would attempt a follow script store every player in a table, then do the magnitude based on that, although it might not handle multiple inputs so maybe i should only make it handle all players and not the closest one.

actually yes, I should make it not handle the closest one am i brain dead lol.

Well, you may want to raycast to see if player is behind a wall or something.

1 Like