Advertisement
ExluZive

Untitled

Aug 18th, 2024 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local character = player.Character or player.CharacterAdded:Wait()
  3.  
  4. -- Функция для нахождения ближайшего игрока
  5. local function findClosestPlayer()
  6. local closestPlayer = nil
  7. local closestDistance = math.huge -- бесконечно большое число
  8.  
  9. for _, otherPlayer in pairs(game.Players:GetPlayers()) do
  10. if otherPlayer ~= player then
  11. local otherCharacter = otherPlayer.Character
  12. if otherCharacter and otherCharacter:FindFirstChild("HumanoidRootPart") then
  13. local distance = (character.HumanoidRootPart.Position - otherCharacter.HumanoidRootPart.Position).Magnitude
  14. if distance < closestDistance then
  15. closestDistance = distance
  16. closestPlayer = otherPlayer
  17. end
  18. end
  19. end
  20. end
  21.  
  22. return closestPlayer
  23. end
  24.  
  25. -- Функция для телепортации к ближайшему игроку
  26. local function teleportToClosestPlayer()
  27. local closestPlayer = findClosestPlayer()
  28.  
  29. if closestPlayer and closestPlayer.Character and closestPlayer.Character:FindFirstChild("HumanoidRootPart") then
  30. character:SetPrimaryPartCFrame(closestPlayer.Character.HumanoidRootPart.CFrame)
  31. print("Телепортирован к: " .. closestPlayer.Name)
  32. else
  33. print("Нет ближайшего игрока для телепортации.")
  34. end
  35. end
  36.  
  37. -- Пример вызова функции телепортации
  38. teleportToClosestPlayer()
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement