Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---local
- local Player = game:GetService("Players").LocalPlayer
- local updatecharacter = Player:WaitForChild("RemoteEvent")
- repeat wait() until Player.Character and Player.Character.PrimaryPart
- local deltatime = os.clock()
- while task.wait(0.1) do
- if Player.Character then
- local a = os.clock()
- updatecharacter:FireServer(a - deltatime, Player.Character.PrimaryPart.Position)
- deltatime = a
- else
- local a = os.clock()
- updatecharacter:FireServer(a - deltatime)
- deltatime = a
- end
- end
- -- Note: you can reduce the wait time
- -- ^ This increases what the server has to handle (by alot alot), 0.1 is good enough?
- -- Increasing the wait time will cause false positive as you're giving people more time to move behind a wall, triggering anti noclip
- --------------------------------------------------------server---------------------------------------------------------------------
- -- Create a new RemoteEvent
- local remote = Instance.new("RemoteEvent")
- local player = game:GetService("Players")
- -- Location table
- -- Used to get real, actual character position/teleporting the player
- _G.Locations = {}
- -- Time table, used for anti bypass
- local timeTable = {}
- -- Anti Noclip function
- -- Not ideal as you can skip corners + the raycast can go into a 0.001 stud hole (that's on you to prevent)
- local raycastParams = RaycastParams.new()
- raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
- local function noclip(p, old, pos, ignore)
- -- Get direction with the correct length
- local a = pos - old
- local direction = a.Unit*a.Magnitude
- -- Raycasting
- raycastParams.FilterDescendantsInstances = {p.Character, workspace.Camera, ignore}
- local raycastResult = workspace:Raycast(old, direction, raycastParams)
- -- Check result, if nothing exist then it hit air we should just continue
- if raycastResult then
- -- Check collision, if false then continue raycasting while ignoring that part it hit.
- if raycastResult.Instance.CanCollide then
- return true
- else
- return noclip(p, raycastResult.Position, pos, raycastResult.Instance)
- end
- else
- return false
- end
- end
- -- Horizontal check
- local function horizontal(distance, dt, p)
- -- The *1.25 because Roblox...
- -- You might have to edit that number depending on how high you put the character walkspeed at on the server.
- -- If you don't the client can increase speed without detection.
- if distance > dt*p.Character.Humanoid.WalkSpeed*1.25 then
- return true
- else
- return false
- end
- end
- local function playeradded(v)
- local function characteradded(v1)
- --Saves initial location
- task.wait()
- _G.Locations[v.Name] = v1.PrimaryPart.Position
- end
- v.CharacterAdded:Connect(characteradded)
- -- Clone and give the client the remote event so each player gets handled by a different thread
- local newre = remote:Clone()
- newre.Parent = v
- -- The function used to do horizontal magnitude check + anti noclip function
- local function check(p,dt, pos)
- if dt <= 0 or not dt == dt then
- p:Kick("very smart") --ban the dude lol
- end
- -- Add the time
- timeTable[p.Name] = timeTable[p.Name]+dt
- -- Check if character/pos exist
- if p.Character then
- if pos and typeof(pos) == "Vector3" then
- -- Get old location
- local old = _G.Locations[p.Name]
- if horizontal(((old-pos)*Vector3.new(1,0,1)).Magnitude,dt,p) or noclip(p, old, pos) then
- -- They moved too far/They clipped through wall, reset their location
- p.Character.PrimaryPart.Position = old
- else
- -- They passed the checks and successfully updated their location
- _G.Locations[p.Name] = pos
- end
- else
- p:Kick("Position is nil/not a Vector3") --ban em
- end
- end
- end
- newre.OnServerEvent:Connect(check)
- local onetime
- onetime = newre.OnServerEvent:Connect(function()
- -- Save initial time when they fire the remote for the first time (indicating they have loaded in)
- -- If they don't fire, their location can not update. They wouldn't be able to move.
- timeTable[v.Name] = os.clock() - 3
- onetime:Disconnect()
- end)
- end
- player.PlayerAdded:Connect(playeradded)
- local function playerremoving(v)
- timeTable[v.Name] = nil
- _G.Locations[v.Name] = nil
- end
- player.PlayerRemoving:Connect(playerremoving)
- -- The anti bypass
- task.spawn(function()
- while task.wait(1) do
- local a = os.clock()
- -- Get all players time
- for i,v in pairs(timeTable) do
- print(a - v)
- -- If somehow their time passed the server time by 1 seconds or slower than 30 seconds
- -- We ban/kick them
- -- Actually, BAN THEM IF THEY EXCEEDED THE SERVER TIME HOW IS THAT POSSIBLE WITHOUT CHEATS
- if v > a + 1 then
- player[i]:Kick("HAS TOO MUCH TIME HOW")
- elseif a - v > 30 then
- player[i]:Kick("Ran out of time")
- end
- end
- -- Magnitude check to prevent not firing the correct location/not firing at all for the server to get time
- for i,v in pairs(_G.Locations) do
- if (player[i].Character.PrimaryPart.Position - v).Magnitude > 20 then -- Change 20 to your allowed distance
- player[i].Character.PrimaryPart.Position = v --go ban them instead?
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement