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

How to check what players are in a specific area?

Asked by
dirk2999 103
5 years ago

Making a minigame game. The players walk into the room to be in the game, how do I check what players are in that specific area?

0
use a touch event or check their coordinates 4D_X 118 — 5y
0
Im not an expert but I would use an invisible Part with a touch event Nickelz 37 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Hi there!

ProgrammerColton here.

There is various ways that you can accomplish this which can be found in the following statements:

1) Magnitude - Using magnitude, you can check if the player is within the range of a certain block.

wiki post can be found here

2) .Touched - Using a touched event, you can check if the player currently touching a brick that is within a certain sector (or area). Such as, if the players walk into a room, add an invisible block in the door frame and when they touch it, add them to a list of current players that are willing to play the minigame.

wiki post can be found here

3) Raycast - Using a raycast, you could shoot a raycast upwards and detect if the player walks under a certain block thats above the specific area that you are talking about.

wiki post can be found here

Best Regards,

  • ProgrammerColton
0
you can use FindPartsInRegion3 look at my answer to see what im talking about mattchew1010 396 — 5y
0
@mattchew1010 I've never worked with "FindPartsInRegion3", thus why I didn't explain to use it. (because I don't know how to use it either :P) DeveloperColton 229 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

make a part in your building the size of the inside but make sure the part is a square then make its transparency 1 then add this script in the workspace or server script service

local plrs = {}
function CreateRegion3FromPart(Part)
    return Region3.new(Part.Position-(Part.Size/2),  Part.Position + (Part.Size/2))
end
function GetPlayersInRegion(Part)
    local region =  CreateRegion3FromPart(Part)
    local plrfound = false
    local InRegion = workspace:FindPartsInRegion3(region,nil,math.huge)--math.Huge is the player limit for example if i want a max 5 people change math.huge to 5

    for i,v in pairs(plrs) do -- clearing all the players in the table so if a player leaves the area the script dosent run for them
        table.remove(plrs, i)
    end
    for i, part in pairs(InRegion) do -- part is like a leg or arm
        local plr = game.Players:GetPlayerFromCharacter(part.Parent)
        if plr then
            for i,v in pairs(plrs) do
                if plrs[i] == plr.Name then
                    plrfound = true
                end
            end
            if plrfound == false then
                table.insert(plrs, plr.Name)
            end
            plrfound = false-- resetting value for next player
        end
    end
end
while true do
    wait() 
    GetPlayersInRegion(workspace.Example) --change workspace.Example to your part
    for i,v in pairs(plrs) do
        wait()-- nessary or theres alot of lag
        if plrs then
        print(plrs[i]) -- do what ever you want like kill them or just print their name
        end
    end
end

Answer this question