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?
How to get all players within 100 studs of a player?
1 answer
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
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