Advertisement
C-H-4-0-S

Aram's anti fling

Apr 2nd, 2024 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3.  
  4. local teleportDistance = 4
  5. local player = game.Players.LocalPlayer
  6.  
  7. local function distance(pos1, pos2)
  8. return (pos1 - pos2).magnitude
  9. end
  10.  
  11. local function teleportAway(otherPosition)
  12. local direction = (player.Character.PrimaryPart.Position - otherPosition).unit
  13. local newPosition = otherPosition + direction * teleportDistance
  14. player.Character:SetPrimaryPartCFrame(CFrame.new(newPosition))
  15. end
  16.  
  17. local function checkProximity()
  18. local myPosition = player.Character and player.Character.PrimaryPart and player.Character.PrimaryPart.Position
  19. if not myPosition then return end
  20.  
  21. for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
  22. if otherPlayer ~= player then
  23. local otherPosition = otherPlayer.Character and otherPlayer.Character.PrimaryPart and otherPlayer.Character.PrimaryPart.Position
  24. if otherPosition and distance(myPosition, otherPosition) < teleportDistance then
  25. teleportAway(otherPosition)
  26. end
  27. end
  28. end
  29. end
  30.  
  31. RunService.Heartbeat:Connect(checkProximity)
  32.  
  33. local Players = game:GetService("Players")
  34. local Character = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
  35. local Torso = Character:WaitForChild("Torso")
  36.  
  37. local proximityThreshold = 3 -- Adjust this value to set the distance threshold for triggering the anchor
  38.  
  39. local function checkProximity()
  40. local closestPlayer = nil
  41. local minDistance = proximityThreshold
  42.  
  43. for _, player in ipairs(Players:GetPlayers()) do
  44. if player ~= Players.LocalPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
  45. local distance = (Torso.Position - player.Character.HumanoidRootPart.Position).magnitude
  46. if distance < minDistance then
  47. closestPlayer = player
  48. minDistance = distance
  49. end
  50. end
  51. end
  52.  
  53. if closestPlayer then
  54. Torso.Anchored = true
  55. else
  56. Torso.Anchored = false
  57. end
  58. end
  59.  
  60. while true do
  61. checkProximity()
  62. wait(0.1) -- Adjust this value as needed for the frequency of proximity checks
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement