Hey guys since I was making more commands beside just the ban command in this script I feel like it might be better to show the whole script instead of the ban stuff.
local dataStore = dataStoreService:GetDataStore("dataStore")
local kickcommand = "!kick "
local bancommand = "!ban "
local unbancommand = "!unban "
local GroupId = 13646742
local RankIDOne = 255
local RankIDTwo = 23
local function kickFunc(name)
for _, player in pairs(game.Players:GetPlayers()) do
local targetedPlr = string.find(player.Name:lower(),name)
if targetedPlr then
player:Kick("You were kicked!")
end
end
end
local function banFunc(name)
for _, player in pairs(game.Players:GetPlayers()) do
local targetedPlr = string.find(player.Name:lower(),name)
if targetedPlr then
print("Hi")
player:FindFirstChild("bannedVal").Value = true
player:Kick("You have been banned!")
end
end
end
local function unBanFunc(name)
for _, player in pairs(game.Players:GetPlayers()) do
local targetedPlr = string.find(player.Name:lower(),name)
if targetedPlr then
player:FindFirstChild("bannedVal").Value = false
end
end
end
game.Players.PlayerAdded:Connect(function(player)
if player:FindFirstChild("bannedVal") == true then
print("Banning again")
player:Kick("You can't join back because you are banned.")
print("Banned")
end
local bannedVal = Instance.new("BoolValue",player)
bannedVal.Name = "bannedVal"
player.Chatted:Connect(function(message)
if string.sub(message,1,string.len(kickcommand)):lower() == kickcommand:lower() then
local UserName = string.sub(message,string.len(kickcommand) + 1):lower()
kickFunc(UserName)
end
end)
player.Chatted:Connect(function(message)
if string.sub(message,1,string.len(bancommand)):lower() == bancommand:lower() then
local UserName = string.sub(message,string.len(bancommand) + 1):lower()
banFunc(UserName)
bannedVal.Value = true
end
end)
player.Chatted:Connect(function(message)
if string.sub(message,1,string.len(unbancommand)):lower() == unbancommand:lower() then
local UserName = string.sub(message,string.len(unbancommand) + 1):lower()
unBanFunc(UserName)
end
end)
local playerId = "Player_"..player.UserId
local data
local suc,err = pcall(function()
data = dataStore:GetAsync(playerId)
end)
if suc then
bannedVal.Value = data
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerId = "Player_"..player.UserId
local data = player:FindFirstChild("bannedVal").Value
local suc, err = pcall(function()
dataStore:SetAsync(playerId,data)
end)
if suc then
else
warn(err)
end
end)