3DCreator

BanHandler

Apr 8th, 2022 (edited)
2,598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. -- Ban/Unban Command Created by OFX7X
  2.  
  3. --If it does not work comment on my youtube channel or message me on discord: OFX7X#2421
  4.  
  5. local DataStoreService = game:GetService("DataStoreService")
  6. local BanStore = DataStoreService:GetDataStore("BanStore1")
  7. local Players = game:GetService("Players")
  8. local Whitelists = require(script:WaitForChild("Whitelists"))
  9.  
  10. Players.PlayerAdded:Connect(function(Player)
  11.     local Data = BanStore:GetAsync(Player.UserId)
  12.  
  13.     if Data then
  14.         Player:Kick("You are banned")
  15.     end
  16.  
  17.     Player.Chatted:Connect(function(Message)
  18.         if table.find(Whitelists, Player.UserId) then
  19.             local Arguments = Message:split(" ")
  20.  
  21.             if Arguments[1]:lower() == "/ban" then
  22.                 if Arguments[2] then
  23.                     local PlayerId = Players:GetUserIdFromNameAsync(Arguments[2])
  24.                     if PlayerId then
  25.                         BanStore:SetAsync(PlayerId, true)
  26.                         for _, Plr in pairs(Players:GetPlayers()) do
  27.                             if Plr.Name:lower() == Arguments[2]:lower() then
  28.                                 Plr:Kick("You have been banned")
  29.                             end
  30.                         end
  31.                     end
  32.                 end
  33.             elseif Arguments[1]:lower() == "/unban" then
  34.                 if Arguments[2] then
  35.                     local PlayerId = Players:GetUserIdFromNameAsync(Arguments[2])
  36.                     if PlayerId then
  37.                         if BanStore:GetAsync(PlayerId) then
  38.                             BanStore:RemoveAsync(PlayerId)
  39.                         end
  40.                     end
  41.                 end
  42.             end
  43.         end
  44.     end)
  45. end)
Add Comment
Please, Sign In to add comment