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

How would i get how many players are in a certain area?

Hi, I'm sort of new roblox scripting (just learnt raycasting) and am trying to make a small minigame game. When the timer runs out, I want to get how many players are in the playing field and give them all a win, but don't know how to get how many players there are. I've heard of Region3s and think thats how but don't know how to use them. Image (The semi-transaprent cylinder is where i want to know where it is.) : https://ibb.co/HgsnYLB

Any help appreciated

5 comments

0

Region3s are strictly rectangular, unfortunately, as you define them between two different Vector3s. To find how many players are in a region, use :FindPartsInRegion3 and then :GetPlayerFromCharacter() on the return. https://developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartsInRegion3

0

How would i do it for cylinders them?

0

I really don't think you can with a Region3. You could try using magnitude, but you'd have to mess around with the distance a lot. Specifically, you'd have to pay attention to each component of the vector, to make sure your bounds are actually cylinder-like. https://developer.roblox.com/en-us/articles/Magnitude

0

Consider using tables instead of a Region3. If you need, I could give you a code demonstration.

0

region3 worked fine for me

1 answer

The issue with Region3's is that they are strictly rectangular and cannot be rotated. Additionally, they're not entirely accurate because they use the voxel system to search for the parts, so the area searched won't match up exactly with the dimensions you gave it.

What you could do is use the actual cylinder part as a sort of hitbox, and use GetTouchingParts() to detect the parts currently inside. You can use this trick to allow the part to remain CanCollide false.

Alternatively you could try out EgoMoose's Rotated Region3 module

5 comments

0

I got the GetTouchingParts working, but how would I get the player from it?

0

You could find the character by checking to see if the part is a descendant of a model that contains a humanoid, then add this character to a table so that you don't detect a 'new' character for every body part. Then go through this table of characters and call game.Players:GetPlayerFromCharacter(char) to get the player object.

0

Actually ill just make a part that has transparency = 1 and cancollide = false and make a region 3 out of that.

0

you dont have to have a part to make a region3. you just have to have two vector3s as its bounds

0

Even when using a Region3, you're just able to get a table of parts, so you'll need to do the same thing that I suggested in my comment anyway to find the players.

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