Answered by
4 years ago Edited 4 years ago
The problem with your code was that the Region
you had created at line 1
was not the same Position
as the hitbox part you had created on line 3
.
I tried creating objects for the Min
and Max
Vector
for the region. That resulted both of them being outside of the hitbox part.
You're now not required to having a hitbox part. You're now defining the Position
, and Size
as a variable at the top.
You're free to remove the code from line 12
to line 18
if you want to. It'll only provide you a means of debugging.
02 | local playersService = game:GetService( "Players" ) |
04 | local sizeX, sizeY, sizeZ = 10 , 10 , 10 |
05 | local hitboxPosition = Vector 3. new( 0 , 5 , 0 ) |
07 | local upperCorner = hitboxPosition + Vector 3. new(sizeX/ 2 , sizeY/ 2 , sizeZ/ 2 ) |
08 | local lowerCorner = hitboxPosition - Vector 3. new(sizeX/ 2 , sizeY/ 2 , sizeZ/ 2 ) |
10 | local region = Region 3. new(lowerCorner, upperCorner) |
12 | local hitbox = Instance.new( "Part" ) |
13 | hitbox.Parent = workspace |
15 | hitbox.Size = region.Size |
16 | hitbox.CFrame = region.CFrame |
17 | hitbox.CanCollide = false |
18 | hitbox.Transparency = 0.75 |
21 | local partsInRegion = workspace:FindPartsInRegion 3 (region, nil , math.huge ) |
22 | for _, part in pairs (partsInRegion) do |
23 | local player = playersService:GetPlayerFromCharacter(part.Parent) |
25 | local character = part.Parent |
26 | local humanoid = character:FindFirstChild( "Humanoid" ) |
27 | humanoid:TakeDamage(humanoid.MaxHealth) |