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

Detecting a player in Region3?

Asked by 3 years ago

CODE:



region = Region3.new(Vector3.new(-13.375, 1.85, 6.58),Vector3.new(7.63, 3.7, 5.12)) while true do wait() for i,v in pairs(game.Workspace:FindPartsInRegion3(region,nil,1000)) do if v:FindFirstChild("Humanoid") then ---do crap here end end end

I'm having trouble finding what I need. ALL I wanna do is if a player is in this region, do this. AND if a player leaves, stop this.

0
^ Obviously the code doesn SooGloezNoob 45 — 3y
0
n't work* SooGloezNoob 45 — 3y

1 answer

Log in to vote
2
Answered by 3 years ago
Edited 3 years ago

To find a player, you need to use :GetPlayerFromCharacter(), because :FindPartsInRegion3() will be detecting a part, which will be a child of the player's character.

In addition to your code, then...

region = Region3.new(Vector3.new(-13.375, 1.85, 6.58),Vector3.new(7.63, 3.7, 5.12))

while true do
    wait(.1) --you probably don't need a loop iterating so quickly
    for i,v in pairs(game.Workspace:FindPartsInRegion3(region,nil,1000)) do
        if v.Parent:FindFirstChild("Humanoid") then --determine if it's player-like
            local Player = game:GetService("Players"):GetPlayerFromCharacter(v.Parent)
            if Player then --confirm it is a real player
                --do code
            else
                --do code for player leaving
            end
        end
    end
end
1
thank you this worked. How would I make it so when the player leaves the region, whatever happens? SooGloezNoob 45 — 3y
0
Well, it is wrapped in an infinite loop. Thus, you can just add an `else` to the `if` statement. See my edited code. Gey4Jesus69 2705 — 3y
0
Accept and upvote if this helps Gey4Jesus69 2705 — 3y
Ad

Answer this question