I need to write a function that returns the distance between two models. Any help?
local function findDistance(position1, position2) --Takes two Vector3 arguments local X1 = position1.X; local X2 = position2.X; local Y1 = position1.Y; local Y2 = position2.Y; local Z1 = position1.Z; local Z2 = position2.Z; return math.sqrt((X2-X1)^2+(Y2-Y1)^2+(Z2-Z1)^2) end
Or you could have a function that works with both Vector2 and Vector3
local function findDistance(position1, position2) local distance = 0; if position1:IsA("Vector3") and position2:IsA("Vector3") then local X1 = position1.X; local X2 = position2.X; local Y1 = position1.Y; local Y2 = position2.Y; local Z1 = position1.Z; local Z2 = position2.Z; distance = math.sqrt((X2-X1)^2+(Y2-Y1)^2+(Z2-Z1)^2); elseif position1:IsA("Vector2") and position2:IsA("Vector2") then local X1 = position1.X; local X2 = position2.X; local Y1 = position1.Y; local Y2 = position2.Y; distance = math.sqrt((X2-X1)^2+(Y2-Y1)^2) end return distance; end