Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Region3 Is detecting everything except me?

Asked by 5 years ago

So I have an NPC that just scans the area around itself for players. Here's the script ``` local region = Region3.new(Vector3.new(hrp.X - range, hrp.Y - range, hrp.Z - range), Vector3.new(hrp.X + range, hrp.Y + range, hrp.Z + range))

local parts = game.Workspace:FindPartsInRegion3(region)

for a, b in pairs(parts) do

print("----")

print(b.Name)

print(b.Parent.Name)

print("----")

if game.Players:FindFirstChild(b.Parent.Name) then

    print("Found player!")

    person = b.Parent

end

end ``` (hrp is the NPC's HumanoidRootPart) (range = 15)

I get all the outputs but the output spits back everything that isn't part of my character. Here's what the output generally looks like ``` RightUpperArm

Dummy



LeftLowerLeg

Dummy



LeftFoot

Dummy



Handle

Rock *(Note: Rock is just a tool)



Handle

PaperHat



LeftUpperLeg

Dummy


``` Yeah it usually just detects itself and the house around it, even when I walk close. I can provide the entire script if it's neccesary, but I just included what I felt to be important.

0
region3 doesn't like you. greatneil80 2647 — 5y
0
I think my region3 is in the wrong place... is there any way to visualize region3s? DaBrainlessOne 129 — 5y
0
yeah there is, just place parts and see if it is detected. greatneil80 2647 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

This seems hard to debug from afar. Here are some changes I would suggest.

  1. Use GetPlayerFromCharacter. Character models can be renamed and so its better to have the roblox engine figure out player ownership of characters over guessing from the model name.
  2. Visualize your region3 as you previously stated. Doing so is possible by creating a non-collide anchored transparent part with the same dimensions as your region and with the same center. Theoretically the code for that could look like ...

    local region ...
    local visualizingpart = Instance.new("Part")
    visualizingpart.Anchored = true
    visualizingpart.CanCollide = false
    visualizingpart.Transparency = 0.5
    visualizingpart.CFrame = region.CFrame
    visualizingpart.Size = region.Size
    

Other than that I don't see anything wrong with your code just eye-balling it. Check the hierarchy of the player character, perhaps body parts have a parent not named after the player?

Ad

Answer this question