Advertisement
BrianBoy_RB

Untitled

Nov 18th, 2021 (edited)
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.07 KB | None | 0 0
  1. ---local
  2. local Player = game:GetService("Players").LocalPlayer
  3.  
  4. local updatecharacter = Player:WaitForChild("RemoteEvent")
  5.  
  6. repeat wait() until Player.Character and Player.Character.PrimaryPart
  7.  
  8. local deltatime = os.clock()
  9.  
  10. while task.wait(0.1) do
  11.     if Player.Character then
  12.         local a = os.clock()
  13.         updatecharacter:FireServer(a - deltatime, Player.Character.PrimaryPart.Position)
  14.         deltatime = a
  15.     else
  16.         local a = os.clock()
  17.         updatecharacter:FireServer(a - deltatime)
  18.         deltatime = a
  19.     end
  20. end
  21.  
  22.  
  23. -- Note: you can reduce the wait time
  24. -- ^  This increases what the server has to handle (by alot alot), 0.1 is good enough?
  25. -- Increasing the wait time will cause false positive as you're giving people more time to move behind a wall, triggering anti noclip
  26.  
  27.  
  28.  
  29. --------------------------------------------------------server---------------------------------------------------------------------
  30. -- Create a new RemoteEvent
  31. local remote = Instance.new("RemoteEvent")
  32. local player = game:GetService("Players")
  33.  
  34. -- Location table
  35. -- Used to get real, actual character position/teleporting the player
  36. _G.Locations = {}
  37.  
  38. -- Time table, used for anti bypass
  39. local timeTable = {}
  40.  
  41. -- Anti Noclip function
  42. -- Not ideal as you can skip corners + the raycast can go into a 0.001 stud hole (that's on you to prevent)
  43. local raycastParams = RaycastParams.new()
  44. raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
  45. local function noclip(p, old, pos, ignore)
  46.     -- Get direction with the correct length
  47.     local a = pos - old
  48.     local direction = a.Unit*a.Magnitude
  49.     -- Raycasting
  50.     raycastParams.FilterDescendantsInstances = {p.Character, workspace.Camera, ignore}
  51.  
  52.     local raycastResult = workspace:Raycast(old, direction, raycastParams)
  53.  
  54.     -- Check result, if nothing exist then it hit air we should just continue
  55.     if raycastResult then
  56.         -- Check collision, if false then continue raycasting while ignoring that part it hit.
  57.         if raycastResult.Instance.CanCollide then
  58.             return true
  59.         else
  60.             return noclip(p, raycastResult.Position, pos, raycastResult.Instance)
  61.         end
  62.     else
  63.         return false
  64.     end
  65. end
  66.  
  67. -- Horizontal check
  68. local function horizontal(distance, dt, p)
  69.     -- The *1.25 because Roblox...
  70.     -- You might have to edit that number depending on how high you put the character walkspeed at on the server.
  71.     -- If you don't the client can increase speed without detection.
  72.     if distance > dt*p.Character.Humanoid.WalkSpeed*1.25 then
  73.         return true
  74.     else
  75.         return false
  76.     end
  77. end
  78.  
  79. local function playeradded(v)
  80.     local function characteradded(v1)
  81.         --Saves initial location
  82.         task.wait()
  83.         _G.Locations[v.Name] = v1.PrimaryPart.Position
  84.     end
  85.     v.CharacterAdded:Connect(characteradded)
  86.     -- Clone and give the client the remote event so each player gets handled by a different thread
  87.     local newre = remote:Clone()
  88.     newre.Parent = v
  89.     -- The function used to do horizontal magnitude check + anti noclip function
  90.     local function check(p,dt, pos)
  91.         if dt <= 0 or not dt == dt then
  92.             p:Kick("very smart") --ban the dude lol
  93.         end
  94.         -- Add the time
  95.         timeTable[p.Name] = timeTable[p.Name]+dt
  96.         -- Check if character/pos exist
  97.         if p.Character then
  98.             if pos and typeof(pos) == "Vector3" then
  99.                 -- Get old location
  100.                 local old = _G.Locations[p.Name]
  101.                 if horizontal(((old-pos)*Vector3.new(1,0,1)).Magnitude,dt,p) or noclip(p, old, pos) then
  102.                     -- They moved too far/They clipped through wall, reset their location
  103.                     p.Character.PrimaryPart.Position = old
  104.                 else
  105.                     -- They passed the checks and successfully updated their location
  106.                     _G.Locations[p.Name] = pos
  107.                 end
  108.             else
  109.                 p:Kick("Position is nil/not a Vector3") --ban em
  110.             end
  111.         end
  112.     end
  113.     newre.OnServerEvent:Connect(check)
  114.     local onetime
  115.     onetime = newre.OnServerEvent:Connect(function()
  116.         -- Save initial time when they fire the remote for the first time (indicating they have loaded in)
  117.         -- If they don't fire, their location can not update. They wouldn't be able to move.
  118.         timeTable[v.Name] = os.clock() - 3
  119.         onetime:Disconnect()
  120.     end)
  121. end
  122.  
  123. player.PlayerAdded:Connect(playeradded)
  124.  
  125. local function playerremoving(v)
  126.     timeTable[v.Name] = nil
  127.     _G.Locations[v.Name] = nil
  128. end
  129.  
  130. player.PlayerRemoving:Connect(playerremoving)
  131.  
  132. -- The anti bypass
  133. task.spawn(function()
  134.     while task.wait(1) do
  135.         local a = os.clock()
  136.         -- Get all players time
  137.         for i,v in pairs(timeTable) do
  138.             print(a - v)
  139.             -- If somehow their time passed the server time by 1 seconds or slower than 30 seconds
  140.             -- We ban/kick them
  141.             -- Actually, BAN THEM IF THEY EXCEEDED THE SERVER TIME HOW IS THAT POSSIBLE WITHOUT CHEATS
  142.             if v > a + 1 then
  143.                 player[i]:Kick("HAS TOO MUCH TIME HOW")
  144.             elseif a - v > 30 then
  145.                 player[i]:Kick("Ran out of time")
  146.             end
  147.         end
  148.         -- Magnitude check to prevent not firing the correct location/not firing at all for the server to get time
  149.         for i,v in pairs(_G.Locations) do
  150.             if (player[i].Character.PrimaryPart.Position - v).Magnitude > 20 then -- Change 20 to your allowed distance
  151.                 player[i].Character.PrimaryPart.Position = v --go ban them instead?
  152.             end
  153.         end
  154.     end
  155. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement