Finding the distance between 2 models

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to find the distance between 2 models, more specifically 2 character models.
  2. What is the issue? Include screenshots / videos if possible!
    I don’t understand how to find this distance.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I attempted to look at the docs, but was unsuccessful.
1 Like

Find and store the humanoid root parts of both the characters.

local player1 = [player_path].Character:FindFirstChild("HumanoidRootPart")

local player2 =  [player_path].Character:FindFirstChild("HumanoidRootPart")

local distance = (player1-player2).Magnitude

.Magnitude finds the distance between the players in studs.

Thanks to the pivot update, it’s relatively simple to compare distances between models. You’re using this for character models, but this can be used for models in general.

local model1 = workspace.Model1
local model2 = workspace.Model2

local distance = (model2:GetPivot().Position - model1:GetPivot().Position).Magnitude
1 Like

Thank you for the support! I will use this to my fullest ability.

I don’t know what [player_path] is, and I don’t feel like learning about it.

[player_path] was just the route to the players. I was just feeling lazy and didn’t feel like writing the entire path all out.

for example. game.Players.Bactraxed would be the player path

i understand, though. there was a few mistakes in my code, though, so it wouldn’t have worked anyway lol.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.