Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- -- Функция для нахождения ближайшего игрока
- local function findClosestPlayer()
- local closestPlayer = nil
- local closestDistance = math.huge -- бесконечно большое число
- for _, otherPlayer in pairs(game.Players:GetPlayers()) do
- if otherPlayer ~= player then
- local otherCharacter = otherPlayer.Character
- if otherCharacter and otherCharacter:FindFirstChild("HumanoidRootPart") then
- local distance = (character.HumanoidRootPart.Position - otherCharacter.HumanoidRootPart.Position).Magnitude
- if distance < closestDistance then
- closestDistance = distance
- closestPlayer = otherPlayer
- end
- end
- end
- end
- return closestPlayer
- end
- -- Функция для телепортации к ближайшему игроку
- local function teleportToClosestPlayer()
- local closestPlayer = findClosestPlayer()
- if closestPlayer and closestPlayer.Character and closestPlayer.Character:FindFirstChild("HumanoidRootPart") then
- character:SetPrimaryPartCFrame(closestPlayer.Character.HumanoidRootPart.CFrame)
- print("Телепортирован к: " .. closestPlayer.Name)
- else
- print("Нет ближайшего игрока для телепортации.")
- end
- end
- -- Пример вызова функции телепортации
- teleportToClosestPlayer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement