Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

3 comments

0

Thanks, any way to do this within a circular radius though?

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

0

hope this helps

This discussion is preserved as it was. New answers, comments, and votes are closed.