Say I want to constantly check the distance between any given character and an object.
Using a while loop isn't that effective, and functions would fire just as much.
What's the most efficient way?
Usually for something like that you would use an event to keep it efficient. For this specific situation I would recommend the 'Changed' event for the Part instance. It would go a little something like this..
local char = game.Workspace.Player1 local part = game.Workspace.Object local mag = nil function onChange(property) if property == "Position" then mag = (char.Torso.Position - Object.Position).magnitude end end Object.Changed:connect(onChange) char.Torso.Changed:connect(onChange)
Hope that helps!