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

How do I get distance inbetween parts?

Asked by 6 years ago

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?

0
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() tkddude2 75 — 6y

1 answer

Log in to vote
0
Answered by
GingeyLol 338 Moderation Voter
6 years ago
while wait(1) do
local magnitude = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - game.Workspace:FindFirstChild("Baseplate").Position).magnitude
    if magnitude<5 then
        print("HOLY COW!!!")
    end
end

--distance between character and baseplate local script
0
It didnt work CrastificeDude612 71 — 6y
0
can you dont GingeyLol 338 — 6y
Ad

Answer this question