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

How to get all players within 100 studs of a player?

Asked by
gitrog 326 Moderation Voter
7 years ago
Edited 7 years ago

I want a message to print all players within 100 studs of a player, is there some sort of event that can check all the players within 100 studs of another player?

1 answer

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

Here's some basic pseudo code of the logic. It is pretty much "guess and check". You'll have to come up with the full logic yourself. Unfortunately, there is no event to my knowledge that would allow you to know all the players in a 100 stud radius.

while wait() do
    for _,player in pairs(Players:GetPlayer()) do --We go through all players.
        if (player.Character.Torso.Position - LocalPlayer.Character.Torso.Position).magnitude <= 100 then --Execute logic if the magnitude is less than or equal to 100.
            print(player.Name .. " is in the area.")
        end
    end
end

Once again, you'll have to complete the logic but that's a general idea. What we're doing in the script is subtracting the vector values since Vector3 is quite clearly a vector. Taking a trigonometry course may help to understand this concept better. Vector3 is pretty much a point on a 3D plane i.e. X, Y, and Z.

Magnitude is getting the X, Y, and Z and getting the distance from that through the hypotenuse. Similar to the concept of Pythagorean Theorem.
x^2 + y^2 + z^2 = v^2


Hopefully this answered your question. If it did, do not forget to hit the accept answer button if you have any questions, feel free to leave them in the comments below.
0
In your first sentence, did you mean "pseudo code"? Also, I believe you need ".magnitude" after the ")" on line 3 to make the script work chess123mate 5873 — 7y
Ad

Answer this question