Advertisement
C-H-4-0-S

Antifling v2

Apr 20th, 2024 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. -- // Constants \\ --
  2. -- [ Services ] --
  3. local Services = setmetatable({}, {__index = function(Self, Index)
  4. local NewService = game.GetService(game, Index)
  5. if NewService then
  6. Self[Index] = NewService
  7. end
  8. return NewService
  9. end})
  10.  
  11. -- [ LocalPlayer ] --
  12. local LocalPlayer = Services.Players.LocalPlayer
  13.  
  14. -- // Functions \\ --
  15. local function PlayerAdded(Player)
  16. local Detected = false
  17. local Character;
  18. local PrimaryPart;
  19.  
  20. local function CharacterAdded(NewCharacter)
  21. Character = NewCharacter
  22. repeat
  23. wait()
  24. PrimaryPart = NewCharacter:FindFirstChild("HumanoidRootPart")
  25. until PrimaryPart
  26. Detected = false
  27. end
  28.  
  29. CharacterAdded(Player.Character or Player.CharacterAdded:Wait())
  30. Player.CharacterAdded:Connect(CharacterAdded)
  31. Services.RunService.Heartbeat:Connect(function()
  32. if (Character and Character:IsDescendantOf(workspace)) and (PrimaryPart and PrimaryPart:IsDescendantOf(Character)) then
  33. if PrimaryPart.AssemblyAngularVelocity.Magnitude > 50 or PrimaryPart.AssemblyLinearVelocity.Magnitude > 100 then
  34. if Detected == false then
  35. game.StarterGui:SetCore("ChatMakeSystemMessage", {
  36. Text = "Fling Exploit detected, Player: " .. tostring(Player);
  37. Color = Color3.fromRGB(255, 200, 0);
  38. })
  39. end
  40. Detected = true
  41. for i,v in ipairs(Character:GetDescendants()) do
  42. if v:IsA("BasePart") then
  43. v.CanCollide = false
  44. v.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
  45. v.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
  46. v.CustomPhysicalProperties = PhysicalProperties.new(0, 0, 0)
  47. end
  48. end
  49. PrimaryPart.CanCollide = false
  50. PrimaryPart.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
  51. PrimaryPart.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
  52. PrimaryPart.CustomPhysicalProperties = PhysicalProperties.new(0, 0, 0)
  53. end
  54. end
  55. end)
  56. end
  57.  
  58. -- // Event Listeners \\ --
  59. for i,v in ipairs(Services.Players:GetPlayers()) do
  60. if v ~= LocalPlayer then
  61. PlayerAdded(v)
  62. end
  63. end
  64. Services.Players.PlayerAdded:Connect(PlayerAdded)
  65.  
  66. local LastPosition = nil
  67. Services.RunService.Heartbeat:Connect(function()
  68. pcall(function()
  69. local PrimaryPart = LocalPlayer.Character.PrimaryPart
  70. if PrimaryPart.AssemblyLinearVelocity.Magnitude > 250 or PrimaryPart.AssemblyAngularVelocity.Magnitude > 250 then
  71. PrimaryPart.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
  72. PrimaryPart.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
  73. PrimaryPart.CFrame = LastPosition
  74.  
  75. game.StarterGui:SetCore("ChatMakeSystemMessage", {
  76. Text = "You were flung. Neutralizing velocity.";
  77. Color = Color3.fromRGB(255, 0, 0);
  78. })
  79. elseif PrimaryPart.AssemblyLinearVelocity.Magnitude < 50 or PrimaryPart.AssemblyAngularVelocity.Magnitude > 50 then
  80. LastPosition = PrimaryPart.CFrame
  81. end
  82. end)
  83. end)
  84.  
  85. local function antiFling()
  86. local localPlayer = Players.LocalPlayer
  87. local maxVelocityChange = 50 -- Set a maximum allowed change in velocity to detect flinging
  88.  
  89. local lastVelocity = Vector3.new(0, 0, 0)
  90. local lastSafePosition = Vector3.new(0, 5, 0)
  91.  
  92. while true do
  93. RunService.Heartbeat:Wait()
  94. local character = localPlayer.Character
  95. local humanoidRootPart, humanoid = getCharacterComponents(character)
  96.  
  97. if humanoidRootPart and humanoid then
  98. local currentVelocity = humanoidRootPart.Velocity
  99. local velocityChange = (currentVelocity - lastVelocity).Magnitude
  100.  
  101. if velocityChange > maxVelocityChange then
  102. applyAntiFling(humanoidRootPart, lastSafePosition)
  103. else
  104. lastSafePosition = humanoidRootPart.Position
  105. end
  106.  
  107. lastVelocity = currentVelocity
  108. end
  109. end
  110. end
  111.  
  112. antiFling()
  113.  
  114. _G.AntiFlingConfig = {
  115. -- this will remove your rotational velocity every frame
  116. disable_rotation = true;
  117.  
  118. -- this slows you down if you're moving too fast, works well but can give you a low gravity effect
  119. limit_velocity = true;
  120. limit_velocity_sensitivity = 100; -- how fast you have to be moving before you get slowed down
  121. limit_velocity_slow = 0; -- the amount of velocity you keep; a lower number increases how much you slow down by
  122.  
  123. -- stops you from ragdolling or falling over and losing control
  124. anti_ragdoll = true;
  125.  
  126. -- completely freezes you if someone gets too close to you
  127. anchor = false;
  128. smart_anchor = true; -- only anchors if someone is considered flinging, this likely won't detect many flings
  129. anchor_dist = 30; -- how close someone has to be to trigger anchor
  130.  
  131. -- teleport away if someone gets too close
  132. teleport = false;
  133. smart_teleport = true; -- only teleports if someone is considered flinging, this likely won't detect many flings
  134. teleport_dist = 1; -- how close someone has to be to teleport you
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement