Advertisement
MasonMac

Anti-Exploit

Jun 17th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.89 KB | None | 0 0
  1. local kr = script.Parent
  2. local admins = {"Put Player User ID Here"}                          --Admins (will not be banned)
  3. local reason = "You have been banned for cheating/exploiting!"      --Reason for ban
  4. local banning = true
  5.  
  6. --Anti-Cheats
  7. local antiSpeed = true                              --Enable anti speed
  8. local antiFly = true                                --Enable anti fly
  9. local antiJump = true                               --Enable anti jump
  10. local antiTeleport = true                           --Enable anti teleport
  11.  
  12. --Gui
  13. local gui = nil
  14. if kr:FindFirstChild("KR Gui") then
  15.     gui = kr:WaitForChild("KR Gui")             --Reference to anti exploit gui
  16. end
  17.  
  18. --Data Storage
  19. local DSS = game:GetService("DataStoreService")     --Reference to data storage service
  20. dataStore = DSS:GetDataStore("BanList")             --Reference to the games ban list
  21.  
  22. --Anti Jump
  23. local loops = 0                                     --Number of loops
  24. local difference = 0                                --Difference in time between os time
  25.  
  26. --Anti-Speed
  27. local maxSpeed = 30                                 --Max possible speed for player
  28. local speedLoop = 0
  29.  
  30. --Crash A Player
  31. local crash = nil
  32. if script.Crash then
  33.     crash = script.Crash
  34. end
  35.  
  36. --What to do when a player joins the server
  37. function onPlayerAdded(player)
  38.     local character = player.Character or player.CharacterAdded:wait()
  39.     local humanoid = character:WaitForChild("Humanoid")
  40.    
  41.     if gui ~= nil then
  42.         gui:Clone().Parent = player.PlayerGui
  43.     end
  44.    
  45.     isBanned(player)
  46.     repeat
  47.         humanoid.StateChanged:Connect(function(state)
  48.             onStateChanged(state, player, humanoid)
  49.         end)
  50.         wait(1)
  51.         onStateChanged(humanoid:GetState(), player, humanoid)
  52.     until not player.Character
  53. end
  54.  
  55. --Generate Data Key
  56. function generateKey(player)
  57.     local key = "uid_"..player.userId
  58.     return key
  59. end
  60.  
  61. --Admin Check
  62. function isAdmin(player)
  63.     if admins == nil or not next(admins) then
  64.         if player.UserId == game.CreatorId then
  65.             return true
  66.         end
  67.     else
  68.         for i,v in ipairs(admins) do
  69.             if type(v) == "number" then
  70.                 if v == player.UserId or player.UserId == game.CreatorId then
  71.                     return true
  72.                 else
  73.                     return true
  74.                 end
  75.             end
  76.         end
  77.     end
  78. end
  79.  
  80. --Check for ban status
  81. function isBanned(player)
  82.     if banning then
  83.         local key = generateKey(player)
  84.         local admin = isAdmin(player)
  85.        
  86.         if not admin then
  87.             if type(dataStore:GetAsync(key)) == "table" then
  88.                 local banned = dataStore:GetAsync(key)[1]
  89.                 local banTime = dataStore:GetAsync(key)[2]
  90.                
  91.                 local lastTime = dataStore:GetAsync(key)[3]    
  92.                
  93.                 if banned and not admin then
  94.                     if banTime ~= 0 then
  95.                         if os.time() - lastTime >= 60*60*banTime then
  96.                             dataStore:SetAsync(key, {false, 0, 0})
  97.                         else
  98.                             player:Kick()
  99.                             return true
  100.                         end
  101.                     elseif banTime == 0 then
  102.                         player:Kick()
  103.                         return true
  104.                     end
  105.                 else
  106.                     return false
  107.                 end
  108.             else
  109.                 print("A new datastore has been built for " .. player.Name)
  110.                 dataStore:SetAsync(key, {false, 0, 0})
  111.                 return false
  112.             end
  113.         else
  114.             return false
  115.         end
  116.     end
  117. end
  118.  
  119. function checkState(player, antiCheat, state)
  120.     local humanoid = player.Character:FindFirstChild("Humanoid")
  121.     if humanoid then
  122.         if antiCheat == "antiTeleport" then
  123.             if state == Enum.HumanoidStateType.FallingDown then
  124.                 wait(1)
  125.                 return false
  126.             elseif state == Enum.HumanoidStateType.Freefall then
  127.                 wait(1)
  128.                 return false
  129.             elseif state == Enum.HumanoidStateType.Jumping then
  130.                 wait(1)
  131.                 return false
  132.             elseif state == Enum.HumanoidStateType.Climbing then
  133.                 wait(1)
  134.                 return false
  135.             elseif state == Enum.HumanoidStateType.PlatformStanding then
  136.                 wait(1)
  137.                 return false
  138.             elseif state == Enum.HumanoidStateType.Seated then
  139.                 wait(1)
  140.                 return false
  141.             elseif state == Enum.HumanoidStateType.None then
  142.                 wait(1)
  143.                 return false
  144.             elseif state == Enum.HumanoidStateType.Landed then
  145.                 wait(1)
  146.                 return false
  147.             end
  148.            
  149.             if state == Enum.HumanoidStateType.Running then
  150.                 wait(1)
  151.                 return true
  152.             elseif state == Enum.HumanoidStateType.RunningNoPhysics then
  153.                 wait(1)
  154.                 return true
  155.             end
  156.         end
  157.     end
  158. end
  159.  
  160. --Checks what the player character is doing
  161. function checkPosition(player, antiCheat)
  162.     local humanoid = player.Character:WaitForChild("Humanoid")
  163.     if not player.Character:FindFirstChild("Humanoid") then
  164.         return false
  165.     end
  166.    
  167.     if antiCheat == "antiSpeed" then
  168.         if humanoid.Health == 0 then
  169.             return false
  170.         elseif humanoid.Sit then
  171.             return false
  172.         elseif humanoid.PlatformStand then
  173.             return false
  174.         else
  175.             return player.Character:FindFirstChild("HumanoidRootPart").Position
  176.         end
  177.     end
  178. end
  179.  
  180. --Main Anti-Exploit Script
  181. function onStateChanged(state, player, humanoid)
  182.     local key = generateKey(player)
  183.     local adminCheck = isAdmin(player)
  184.    
  185.     if player.Character then
  186.        
  187.         --Anti-Jump Script
  188.         if adminCheck then
  189.             if antiJump then
  190.                 if state == Enum.HumanoidStateType.Seated then
  191.                     if difference > os.time() - 1 then
  192.                         loops = loops + 1
  193.                         if loops > 2 then
  194.                             if not isBanned(player) then
  195.                                 dataStore:SetAsync(key, {true, 168, os.time()})
  196.                                 player:Kick(reason)
  197.                                 print(player.Name .. " has been banned!")
  198.                                 return
  199.                             else
  200.                                 return
  201.                             end
  202.                         end
  203.                     else
  204.                         difference = os.time()
  205.                         loops = 0
  206.                     end
  207.                 end
  208.             end
  209.            
  210.             --Anti-Fly Script
  211.             if antiFly then
  212.                 if state == Enum.HumanoidStateType.Flying then
  213.                     if not isBanned(player) then
  214.                         dataStore:SetAsync(key, {true, 168, os.time()})
  215.                         player:Kick(reason)
  216.                         print(("%s has been banned!"):format(player.Name))
  217.                         return
  218.                     else
  219.                         return
  220.                     end
  221.                 end
  222.             end
  223.            
  224.             --Anti-Speed Script
  225.             if antiSpeed then
  226.                 if humanoid.WalkSpeed > maxSpeed + 2 then
  227.                     if not isBanned(player) then
  228.                         dataStore:SetAsync(key, {true, 168, os.time()})
  229.                         --[[
  230.                         local kick = crash:Clone()
  231.                         kick.Parent = player.Backpack
  232.                         kick.Disabled = false ]]
  233.                         player:Kick()
  234.                         print(("%s has been banned!"):format(player.Name))
  235.                         return
  236.                     else
  237.                         return
  238.                     end
  239.                 end
  240.             end
  241.            
  242.             --Anti-Teleport Script
  243.             if antiTeleport then
  244.                 if checkState(player, "antiTeleport", humanoid:GetState()) then                         --Just to check if the player is NOT jumping/falling
  245.                     local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
  246.                     local playerPosition = humanoidRootPart.Position
  247.                    
  248.                     local timeWaited = wait(1)
  249.                    
  250.                     local currentPosition = humanoidRootPart.Position
  251.                     local speed = (currentPosition - playerPosition).magnitude / timeWaited
  252.                     if speed > humanoid.WalkSpeed + 10 then
  253.                         if not isBanned(player) then
  254.                             currentPosition = playerPosition
  255.                             dataStore:SetAsync(key, {true, 168, os.time()})
  256.                             player:Kick(reason)
  257.                             print(("%s has been banned!"):format(player.Name))
  258.                             return
  259.                         else
  260.                             currentPosition = playerPosition
  261.                             return
  262.                         end    
  263.                     end
  264.                 end
  265.             end
  266.         end
  267.     end
  268.    
  269.     return
  270. end
  271.  
  272. game:GetService("Players").PlayerAdded:Connect(onPlayerAdded)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement