Axolotleless

Basic anti-noclip

Feb 9th, 2025
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.87 KB | None | 0 0
  1. --[[note: make sure your game is in r6 since it might give false positives when in r15 especially on small r15 avatars]]
  2.  
  3. local Players = game:GetService("Players")
  4. local NoclipPart
  5.  
  6. local function CreatePart(Character, RootPart, Humanoid) -- function to create NoclipPart
  7.     local Connections = {}
  8.     local NoclipPart = Instance.new("Part")
  9.     NoclipPart.Size = Vector3.new(.5,.5,.5) -- set the best possible size without false flags
  10.     NoclipPart.CanCollide = true -- cancollide must be true otherwise it won't work
  11.     NoclipPart.Name = math.random(1, 9999)
  12.     NoclipPart.Parent = Character
  13.     local Weld = Instance.new("Weld") -- a weld so the Part stays attached to the RootPart
  14.     Weld.Part0 = NoclipPart
  15.     Weld.Part1 = RootPart
  16.     Weld.Name = math.random(1, 9999)
  17.     Weld.Parent = NoclipPart
  18.    
  19.     NoclipPart.Destroying:Connect(function() -- if RejectCharacterDeletions is set to false this'll make sure the part isn't just destroyed
  20.         if Humanoid and Humanoid.Health > 0 then -- checks to make sure the Player hasn't died
  21.             NoclipPart = CreatePart(Character, RootPart) -- if the player hasn't died then recreate the part
  22.         else
  23.             for _,connection in pairs(Connections) do -- loop through all connections and disconnect them
  24.                 connection:Disconnect()
  25.                 connection = nil
  26.             end
  27.         end
  28.     end)
  29.    
  30.     Weld.Destroying:Connect(function()
  31.         if Humanoid.Health and Humanoid.Health > 0 then
  32.             if Humanoid and Humanoid.Health > 0 then -- checks to make sure the Player hasn't died
  33.                 NoclipPart:Destroy()
  34.                 NoclipPart = CreatePart(Character, RootPart) -- if the player hasn't died then recreate the part
  35.             else
  36.                 for _,connection in pairs(Connections) do
  37.                     connection:Disconnect()
  38.                     connection = nil
  39.                 end
  40.             end
  41.         end
  42.     end)
  43.    
  44.     return NoclipPart
  45. end
  46.  
  47. Players.PlayerAdded:Connect(function(Player)
  48.     Player.CharacterAdded:Connect(function(Character)
  49.         local Humanoid = Character:WaitForChild("Humanoid")
  50.         local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
  51.         NoclipPart = CreatePart(Character, HumanoidRootPart)
  52.        
  53.         while true do
  54.             if Humanoid and Humanoid.Health > 0 then -- check to make sure the player hasn't died
  55.                 for _,Part in pairs(NoclipPart:GetTouchingParts()) do -- loop through all parts touching the NoclipPart
  56.                     if Part:IsA("Part") and Part.Parent ~= Character and Part.CanCollide == true and not Part.Parent:FindFirstChild("Humanoid") then  -- checks to stop false flags
  57.                         local Origin = NoclipPart.Position
  58.                         local Direction = Part.Position
  59.                        
  60.                         local RayParams = RaycastParams.new()
  61.                         RayParams.FilterDescendantsInstances = {Character}
  62.                         RayParams.FilterType = Enum.RaycastFilterType.Exclude -- filter out parts within the Player's Character
  63.                        
  64.                         local RayResults = workspace:Raycast(Origin, Direction, RayParams) -- raycast from the NoclipPart to the touching Part
  65.                        
  66.                         if not RayResults then -- if the raycast returned nil then they must be inside the part because the raycast found no faces to intersect with
  67.                             Humanoid.Health = 0
  68.                             warn(Player.Name,"Triggered anti noclip")
  69.                         end
  70.                     end
  71.                 end
  72.             else
  73.                 break -- break out of the loop if the player has died
  74.             end
  75.             task.wait() -- this can be changed but teleport through parts won't be detected anymore
  76.         end
  77.     end)
  78. end)
  79.  
Advertisement
Add Comment
Please, Sign In to add comment