I am trying to get the distance between a player's HumanoidRootPart and the main fireplace part so that I can make it so that you can light the torch up it in a certain range. I've been trying lots of methods recently for example Roblox's method.
local magnitude = (part1.Position - part2.Position).magnitude
while true do
if magnitude<5 then
--- code ---
end
end
I've replaced part1 and part2 with my parts and it did not work. I've also tried a different method posted on this website 3 years ago.
local player = game.Players.Player1
local radius = 5
if player:DistanceFromCharacter(part) < radius then
print('player is within radius')
end
I've also replaced part with my part and it did not work either. Is this a problem or are my scripting skills still under a rock?

1 comment
The distance is determine when you define the magnitude variable, meaning that it doesn't update as your character moves. You need to move magnitude(your line 1) into the while true do loop so that it updates. Also, you need to add a wait into your loops, so roblox doesn't freeze. You can do so by typing wait()