Advertisement
HowToRoblox

BanHandler

May 15th, 2021
4,901
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 1 0
  1. local admins = {84182809}
  2.  
  3. local timeUnits = {d = 24*60*60, h = 60*60, m = 60, s = 1}
  4.  
  5.  
  6. local dss = game:GetService("DataStoreService")
  7. local banDS = dss:GetDataStore("BanData")
  8.  
  9.  
  10. game.Players.PlayerAdded:Connect(function(plr)
  11.    
  12.    
  13.     local result = nil
  14.     local success, err = pcall(function()
  15.         result = banDS:GetAsync(plr.UserId .. "-BanData")
  16.     end)
  17.    
  18.     if result then
  19.        
  20.         local thenTime = result[1]
  21.         local nowTime = os.time()
  22.         local banTime = result[2]
  23.         local reason = result[3]
  24.         local timeDiff = nowTime - thenTime
  25.        
  26.         if timeDiff < banTime then
  27.            
  28.             local newTime = banTime - timeDiff
  29.            
  30.             plr:Kick(reason .. "\nBanned for " .. newTime .. "s")
  31.            
  32.            
  33.         else
  34.            
  35.             pcall(function()
  36.                 banDS:SetAsync(plr.UserId .. "-BanData", nil)
  37.             end)
  38.         end
  39.     end
  40.    
  41.    
  42.    
  43.     if table.find(admins, plr.UserId) then
  44.        
  45.        
  46.         plr.Chatted:Connect(function(message)
  47.            
  48.             local splitMsg = string.split(message, " ")
  49.            
  50.             local banCmd = splitMsg[1]
  51.             local plrName = splitMsg[2]
  52.             local banTime = splitMsg[3]
  53.             local reason = splitMsg[4] or "Reason unavailable."
  54.            
  55.            
  56.             if banCmd == "!ban" and plrName and banTime then
  57.                
  58.                 local timeUnit = string.sub(banTime, -1, -1)
  59.                 local timeAmount = string.sub(banTime, 1, #banTime-1)
  60.                 local seconds = timeUnits[timeUnit]
  61.                
  62.                
  63.                 if seconds then
  64.                    
  65.                     local plrId = game.Players:GetUserIdFromNameAsync(plrName)
  66.                    
  67.                     if plrId then
  68.                        
  69.                         local banTimeSeconds = seconds * timeAmount
  70.                        
  71.                         pcall(function()
  72.                             banDS:SetAsync(plrId .. "-BanData", {os.time(), banTimeSeconds, reason})
  73.                         end)
  74.                        
  75.                         if game.Players:FindFirstChild(plrName) then
  76.                            
  77.                             game.Players[plrName]:Kick(reason .. "\nBanned for " .. banTime)
  78.                         end
  79.                     end
  80.                 end
  81.             end
  82.         end)
  83.     end
  84. end)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement