5_Gallon_Bucket

Untitled

May 6th, 2022
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. local DDS = game:GetService("DataStoreService");
  2. local pname = game.Players.LocalPlayer.Name;
  3. local Players = game:GetService("Players");
  4. local BanStore = DDS:GetDataStore("BanStore", 2);
  5. local secondsInADay = 86400
  6. local function SetBan(Player, Reason, Duration)
  7.     local Success, Error = pcall(function()
  8.         BanStore:SetAsync(tostring(Player.UserId), {BanStart = os.time(), BanDuration = (Duration * secondsInADay), BanReason = Reason});
  9.     end)
  10.     Player:Kick(Reason);
  11.     if not Success then
  12.         warn("Not successful.")
  13.     end
  14. end
  15. local function GetBan(Player)
  16.     local Success, Result = pcall(function()
  17.         return BanStore:GetAsync(tostring(Player.UserId), "TempBan");
  18.     end)
  19.     if Success then
  20.         if Result then
  21.             if Result.BanStart + Result.BanDuration > os.time() then
  22.                 return nil;
  23.             else
  24.                 return Result.BanReason;
  25.             end
  26.         end
  27.     end
  28. end
  29. Players.PlayerAdded:Connect(function(plr)
  30.     local IsBanned = GetBan(plr);
  31.     if IsBanned ~= nil then
  32.         plr:Kick(IsBanned);
  33.     else
  34.         print("Player's ban has been lifted.");
  35.     end
  36.     if plr.UserId == game.CreatorId then
  37.         plr.Chatted:Connect(function(message)
  38.             if string.sub(message, 1, #"/ban"):lower() == "/ban" then
  39.                 local args = string.split(message, " ");
  40.                 local numbers = "%d" or "%d%d";
  41.                 local duration = string.sub(message, string.find(message, numbers));
  42.                 local playerToBan = Players:FindFirstChild(args[2])
  43.                 local reason = string.sub(message, string.len("/ban " .. args[2] .. " " .. duration) + 1);
  44.                 if playerToBan then
  45.                     if duration then
  46.                         if reason then
  47.                             SetBan(playerToBan, reason, duration);
  48.                             print("Player has been banned!");
  49.                         end
  50.                     end
  51.                 end
  52.             end
  53.         end)
  54.     end
  55. end)
  56.  
Advertisement
Add Comment
Please, Sign In to add comment