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

How do I detect the number of players in a certain area?

Asked by
Dad_Bot 34
6 years ago

If I have an area filled up by a huge invisible non collidable block, how would I detect how many users are inside of that block.

1 answer

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

EDIT

im going to use magitude to get the amount of players in a radius of 50 studs every 30 seconds

i inserted a part into workspace and placed this script inside it

while true do
local list = game.Players:GetChildren() --makes a list of the current players
local counter = 0
local distance = 50 ----as in 50 studs
for i= 1, #list do 

    local plyrpos = list[i].Character:WaitForChild("HumanoidRootPart").Position
    local centerpos = script.Parent.Position

    local testdistance = (plyrpos-centerpos).magnitude--- get magnitude
        if testdistance<=distance then
            counter= counter+1 ----if they are in the region then add to counter
        end

end
print("there are "..counter.." players inside")
count=0
wait(30)
end

here (the green part is 50 studs long). when 3 players are inside 50 stud radius it prints 3 players

here is a test with a single player inside the radius

here the blue sphere is the actual depiction of the region.

0
Thanks, any way to do this within a circular radius though? Dad_Bot 34 — 6y
0
the only way i can think of is using .magnitude. probably make a counter and place a part in the middle, then get the players, and if a player is within say 100 studs then add 1 to the counter, when its done checking the player list then print counter deerdharok 91 — 6y
0
hope this helps deerdharok 91 — 6y
Ad

Answer this question