Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local kr = script.Parent
- local admins = {"Put Player User ID Here"} --Admins (will not be banned)
- local reason = "You have been banned for cheating/exploiting!" --Reason for ban
- local banning = true
- --Anti-Cheats
- local antiSpeed = true --Enable anti speed
- local antiFly = true --Enable anti fly
- local antiJump = true --Enable anti jump
- local antiTeleport = true --Enable anti teleport
- --Gui
- local gui = nil
- if kr:FindFirstChild("KR Gui") then
- gui = kr:WaitForChild("KR Gui") --Reference to anti exploit gui
- end
- --Data Storage
- local DSS = game:GetService("DataStoreService") --Reference to data storage service
- dataStore = DSS:GetDataStore("BanList") --Reference to the games ban list
- --Anti Jump
- local loops = 0 --Number of loops
- local difference = 0 --Difference in time between os time
- --Anti-Speed
- local maxSpeed = 30 --Max possible speed for player
- local speedLoop = 0
- --Crash A Player
- local crash = nil
- if script.Crash then
- crash = script.Crash
- end
- --What to do when a player joins the server
- function onPlayerAdded(player)
- local character = player.Character or player.CharacterAdded:wait()
- local humanoid = character:WaitForChild("Humanoid")
- if gui ~= nil then
- gui:Clone().Parent = player.PlayerGui
- end
- isBanned(player)
- repeat
- humanoid.StateChanged:Connect(function(state)
- onStateChanged(state, player, humanoid)
- end)
- wait(1)
- onStateChanged(humanoid:GetState(), player, humanoid)
- until not player.Character
- end
- --Generate Data Key
- function generateKey(player)
- local key = "uid_"..player.userId
- return key
- end
- --Admin Check
- function isAdmin(player)
- if admins == nil or not next(admins) then
- if player.UserId == game.CreatorId then
- return true
- end
- else
- for i,v in ipairs(admins) do
- if type(v) == "number" then
- if v == player.UserId or player.UserId == game.CreatorId then
- return true
- else
- return true
- end
- end
- end
- end
- end
- --Check for ban status
- function isBanned(player)
- if banning then
- local key = generateKey(player)
- local admin = isAdmin(player)
- if not admin then
- if type(dataStore:GetAsync(key)) == "table" then
- local banned = dataStore:GetAsync(key)[1]
- local banTime = dataStore:GetAsync(key)[2]
- local lastTime = dataStore:GetAsync(key)[3]
- if banned and not admin then
- if banTime ~= 0 then
- if os.time() - lastTime >= 60*60*banTime then
- dataStore:SetAsync(key, {false, 0, 0})
- else
- player:Kick()
- return true
- end
- elseif banTime == 0 then
- player:Kick()
- return true
- end
- else
- return false
- end
- else
- print("A new datastore has been built for " .. player.Name)
- dataStore:SetAsync(key, {false, 0, 0})
- return false
- end
- else
- return false
- end
- end
- end
- function checkState(player, antiCheat, state)
- local humanoid = player.Character:FindFirstChild("Humanoid")
- if humanoid then
- if antiCheat == "antiTeleport" then
- if state == Enum.HumanoidStateType.FallingDown then
- wait(1)
- return false
- elseif state == Enum.HumanoidStateType.Freefall then
- wait(1)
- return false
- elseif state == Enum.HumanoidStateType.Jumping then
- wait(1)
- return false
- elseif state == Enum.HumanoidStateType.Climbing then
- wait(1)
- return false
- elseif state == Enum.HumanoidStateType.PlatformStanding then
- wait(1)
- return false
- elseif state == Enum.HumanoidStateType.Seated then
- wait(1)
- return false
- elseif state == Enum.HumanoidStateType.None then
- wait(1)
- return false
- elseif state == Enum.HumanoidStateType.Landed then
- wait(1)
- return false
- end
- if state == Enum.HumanoidStateType.Running then
- wait(1)
- return true
- elseif state == Enum.HumanoidStateType.RunningNoPhysics then
- wait(1)
- return true
- end
- end
- end
- end
- --Checks what the player character is doing
- function checkPosition(player, antiCheat)
- local humanoid = player.Character:WaitForChild("Humanoid")
- if not player.Character:FindFirstChild("Humanoid") then
- return false
- end
- if antiCheat == "antiSpeed" then
- if humanoid.Health == 0 then
- return false
- elseif humanoid.Sit then
- return false
- elseif humanoid.PlatformStand then
- return false
- else
- return player.Character:FindFirstChild("HumanoidRootPart").Position
- end
- end
- end
- --Main Anti-Exploit Script
- function onStateChanged(state, player, humanoid)
- local key = generateKey(player)
- local adminCheck = isAdmin(player)
- if player.Character then
- --Anti-Jump Script
- if adminCheck then
- if antiJump then
- if state == Enum.HumanoidStateType.Seated then
- if difference > os.time() - 1 then
- loops = loops + 1
- if loops > 2 then
- if not isBanned(player) then
- dataStore:SetAsync(key, {true, 168, os.time()})
- player:Kick(reason)
- print(player.Name .. " has been banned!")
- return
- else
- return
- end
- end
- else
- difference = os.time()
- loops = 0
- end
- end
- end
- --Anti-Fly Script
- if antiFly then
- if state == Enum.HumanoidStateType.Flying then
- if not isBanned(player) then
- dataStore:SetAsync(key, {true, 168, os.time()})
- player:Kick(reason)
- print(("%s has been banned!"):format(player.Name))
- return
- else
- return
- end
- end
- end
- --Anti-Speed Script
- if antiSpeed then
- if humanoid.WalkSpeed > maxSpeed + 2 then
- if not isBanned(player) then
- dataStore:SetAsync(key, {true, 168, os.time()})
- --[[
- local kick = crash:Clone()
- kick.Parent = player.Backpack
- kick.Disabled = false ]]
- player:Kick()
- print(("%s has been banned!"):format(player.Name))
- return
- else
- return
- end
- end
- end
- --Anti-Teleport Script
- if antiTeleport then
- if checkState(player, "antiTeleport", humanoid:GetState()) then --Just to check if the player is NOT jumping/falling
- local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
- local playerPosition = humanoidRootPart.Position
- local timeWaited = wait(1)
- local currentPosition = humanoidRootPart.Position
- local speed = (currentPosition - playerPosition).magnitude / timeWaited
- if speed > humanoid.WalkSpeed + 10 then
- if not isBanned(player) then
- currentPosition = playerPosition
- dataStore:SetAsync(key, {true, 168, os.time()})
- player:Kick(reason)
- print(("%s has been banned!"):format(player.Name))
- return
- else
- currentPosition = playerPosition
- return
- end
- end
- end
- end
- end
- end
- return
- end
- game:GetService("Players").PlayerAdded:Connect(onPlayerAdded)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement