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

How do I identify how many studs are between a player and object?

Asked by
Dominical 215 Moderation Voter
10 years ago

I am wanting to find how many studs are between an object(a part) and a player(character model).

What I thought of that didn't work:

firstpart = workspace.Part
playerTorso = workspace.Player1.Torso



math.max(firstpart,playerTorso)-math.min(firstpart,playerTorso)

How could I do this?

(Also, I am just making this script to show what I did in a simplified version, I know it would be an error if I ran the script I provided)

1 answer

Log in to vote
2
Answered by
Discern 1007 Moderation Voter
10 years ago

You would use magnitude. It gets the distance between 2 Vector3 Values.

firstpart = workspace.Part
playerTorso = workspace.Player1.Torso

local distance = (firstpart.Position - playerTorso.Position).magnitude

You would use "distance" to refer to the distance at any time.

You can read more on magnitude here.

Hope I helped. :)

0
You did. I just remembered this term right when I saw the word magnitude. I feel so stupid LOL Thanks for helping! Dominical 215 — 10y
Ad

Answer this question