✓ Accepted answer
There are two ways to check for a distance in roblox that I usually use for this sort of thing. The first is a method of the roblox Player object:
local player = game.Players.Player1
local radius = 5
if player:DistanceFromCharacter(Vector3.new(1,433,656)) < radius then
print('player is within radius')
end
The other technique involves the use of some simple vector math:
local position1 = Vector3.new(12031,13123,3123)
local position2 = Vector3.new(12031,3123,13123)
local distance = (position1 - position2).magnitude
Basically, I use the first option when I am checking for distances with a player, and have access to the player, and I use the second option when I am just checking distances between random objects or I do not have access to the player.
2 comments
That would solve the main part of my problem. I still need to be constantly testing if the player is within or not the radius. I want to make interactive objects that shows the message "press E to interact" whenever the player is close to it, so i tought of using a while loop or the "Changed" event on the player's Torso that would test for close objects every time the Position changes. Any ideas?
Your ideas are the exact solutions I would suggest. Either the infinite loop or the changed event. The changed event causes much less lag however, so that would be the best option imo.