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

How can I constantly print the distance between the Player's Torso and a Part?

Asked by 8 years ago
Edited 8 years ago

I am trying to constantly print the Distance between the Torso and a Part in the workspace, I have literally tried every loop and cannot solve this. Any and all help is welcomed and appreciated, here is my code(script is in StarterCharacterScripts)

Torso = script.Parent.Torso
magnitude = Torso.Position.Magnitude - workspace.One.Position.Magnitude

Value = 0

while Value < 15 do
    Value = Value + 1
    print(magnitude)
    wait(1)
end

I always get the same distance between the two points and even if I move closer to the Part it never changes.

1
You're not updating magnitude. TestingPlace1337 51 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

You have about two problems with your given script. First of all is how you're getting the magnitude, you should do it this way:

local Magnitude = (part.Position - Part.Position).magnitude

Even if the above code was used instead of your method of trying to get magnitude was implemented in your script, it still wouldn't work as you want. The Magnitude variable is already made as a value on line 2 while you never check again and again, causing this variable to consist of the same exact value. So to fix this, you can just do the bellow:

Torso = script.Parent.Torso
magnitude = (Torso.Position  - workspace.One.Position).magnitude

Value = 0

while Value < 15 do
    Value = Value + 1
    magnitude = (Torso.Position  - workspace.One.Position).magnitude -- Now it's updated
    print(magnitude)
    wait(1)
end
Ad

Answer this question