Hello fellow developers, so my recent posts have been regarding me trying to create an attack that teleport you to the nearest player, I’ve finally found a way to find out the closest magnitude from the player but my problem is finding who the closest magnitude belongs to. So I’ve find out how to get the closest magnitude but I don’t know how to find out who it is for.
Heres my script:
script.Parent.OnServerEvent:Connect(function(plr)
local char = plr.Character
local hum = char.Humanoid
local list = {}
local root = char.HumanoidRootPart
for i,v in pairs(workspace:GetChildren()) do
if v:FindFirstChild("HumanoidRootPart") and v ~= char then
local dis = (root.Position - v.HumanoidRootPart.Position).Magnitude
if dis <60 then
table.insert(list,dis)
table.sort(list,function(a,b)
return a < b
end)
end
end
end
print(list[1])
end)
Any help is appreciated, thank you and have a great day!