Greetings, I am currently modifying Basic Admin Essentials 2.0 by @r_r. I have modified the permBan
function, but once I did so, the :pban
command doesn’t work on players in-game anymore. I am very unsure of what I have did wrong.
I have tried debugging this issue, but I had no luck with this. I would like to find out how I would be able to fix this as I really need this command to work for my game to moderate rule breakers. I’ve tried checking the output, and nothing is shown. The :pban
command works perfectly fine when the player is not in-game.
Function Code:
function Funcs.permBan(Args)
local Player = Args[1]
local Cmd = Args[2]
local Players = returnPlayers(Player,Args[3],Args[2])
if Cmd == "pban" or Cmd == "pbanid" then
local Succ, Msg = pcall(function()
local victimTable = {}
local victimName, victimId
local givenReason
if Args[4] then
local combinedArgs = ""
for a, b in pairs(Args) do
if a > 3 then
combinedArgs = combinedArgs .. b .. ' '
end
end
if combinedArgs ~= "" then
givenReason = combinedArgs
end
end
if not Players then
local Success, Msg = pcall(function()
if Cmd == "pban" then
victimId = tonumber(playerService:GetUserIdFromNameAsync(Args[3]))
victimName = tostring(playerService:GetNameFromUserIdAsync(victimId))
else
victimId = tonumber(Args[3])
victimName = tostring(playerService:GetNameFromUserIdAsync(Args[3]))
end
end)
if Success and not Msg then
if not DataCategory.get("PermanentBans") then
DataCategory.set("PermanentBans", {})
end
local existingBans = DataCategory.get("PermanentBans")
local isAlreadyBanned = false
for _, banEntry in pairs(existingBans) do
if tonumber(banEntry.UserId) == tonumber(victimId) then
isAlreadyBanned = true
break
end
end
if not isAlreadyBanned then
if returnPerms_ID(victimId) >= returnPermission(Player) then
return
else
table.insert(victimTable, {victimId, victimName})
local dateTable = {timeAndDate.Date()}
local dateString = dateTable[2] .. '/' .. dateTable[3] .. '/' .. string.sub(dateTable[1], 3)
local reasonString = ''
if givenReason then
local Cleaned, newData = cleanUserData(givenReason, Player, false)
if Cleaned and newData then
givenReason = newData
elseif not Cleaned then
if newData and newData:lower():match('cannot communicate with') then
givenReason = 'A reason was provided, but your privacy settings prevent you from seeing it.'
else
if not newData then
remoteEvent:FireClient(Player, 'Message', sysTable.serverMessage, 'Your chat settings prevent you from communicating in any way, so a reason will not be provided.')
givenReason = nil
else
givenReason = newData
end
end
end
if givenReason ~= nil then
reasonString = ', Reason: ' .. givenReason
end
end
local Succ, Msg = pcall(function()
local updatedBans = DataCategory.get("PermanentBans")
table.insert(updatedBans, {
Name = victimName,
UserId = victimId,
Moderator = Player.Name,
Date = dateString,
Reason = givenReason or "No reason provided.",
Type = "Permanent"
})
DataCategory.set("PermanentBans", updatedBans)
end)
-- Add to in-game banned list
table.insert(sysTable.Permissions.Banned, {
Name = victimName,
UserId = victimId,
Moderator = Player.Name,
Date = dateString,
Reason = givenReason,
Type = "Permanent"
})
if not Succ and Msg then
remoteEvent:FireClient(Player, 'Message', 'Error', 'An error occurred while trying to ban that user.')
end
end
end
else
remoteEvent:FireClient(Player, 'Message', 'Error', 'An error occurred while trying to "' .. Cmd .. '"' .. '\n' .. Msg)
return
end
else
for a,b in next,Players do
print(returnPerms_ID(b.UserId))
if returnPerms_ID(b.UserId) < returnPermission(Player) then
table.insert(victimTable,{b.UserId,b.Name})
local dateTable = {timeAndDate.Date()}
local dateString = dateTable[2]..'/'..dateTable[3]..'/'..string.sub(dateTable[1],3)
local reasonString = ''
if givenReason then
local Cleaned, newData = cleanUserData(givenReason, Player, false)
if Cleaned and newData then
givenReason = newData
elseif not Cleaned then
if newData and newData:lower():match('cannot communicate with') then
givenReason = 'A reason was provided, but your privacy settings prevent you from seeing it.'
else
if not newData then
remoteEvent:FireClient(Player, 'Message', sysTable.serverMessage, 'Your chat settings prevent you from communicating in any way, so a reason will not be provided.')
givenReason = nil
else
givenReason = newData
end
end
end
if givenReason ~= nil then
reasonString = ', Reason: ' .. givenReason
end
end
local Succ, Msg = pcall(function()
local updatedBans = DataCategory.get("PermanentBans") or {}
table.insert(updatedBans, {
Name = b.Name,
UserId = b.UserId,
Moderator = Player.Name,
Date = dateString,
Reason = givenReason,
Type = "Permanent"
})
DataCategory.set("PermanentBans", updatedBans)
end)
table.insert(sysTable.Permissions.Banned, {
Name = b.Name,
UserId = b.UserId,
Moderator = Player.Name,
Date = dateString,
Reason = givenReason,
Type = "Permanent"
})
if not Succ and Msg then
remoteEvent:FireClient(Player, 'Message', 'Error', 'An error occurred while trying to ban that user.')
end
b:Kick('Basic Admin\n' .. sysTable.banReason .. '\nPermanently' .. reasonString)
end
end
end
if #victimTable > 0 then
local toSend
for _, b in next, victimTable do
if not toSend then
toSend = b[1] .. ', ' .. b[2]
else
toSend = toSend .. ' | ' .. b[1] .. ', ' .. b[2]
end
end
remoteEvent:FireClient(Player, 'Hint', "Permanently Banned", toSend)
else
remoteEvent:FireClient(Player, 'Hint', "Error", "User already banned, or an unexpected error occurred.")
end
end)
if Msg then
addLog(sysTable.debugLogs, 'Funcs.permBan, "pban", Message: ' .. Msg or "Err")
end
elseif Cmd == "unpban" or Cmd == "unpbanid" then
local Succ, Msg = pcall(function()
local victimId, victimName, Removed
local Succ, Msg = pcall(function()
if Cmd == "unpban" then
victimId = tonumber(playerService:GetUserIdFromNameAsync(Args[3]))
victimName = tostring(playerService:GetNameFromUserIdAsync(victimId))
else
victimId = tonumber(Args[3])
victimName = tostring(playerService:GetNameFromUserIdAsync(Args[3]))
end
end)
if Succ and not Msg then
local bannedStatus
local updatedBans
local Succ, Msg = pcall(function()
updatedBans = DataCategory.get("PermanentBans") or {}
end)
if Succ and updatedBans then
for i, banEntry in ipairs(updatedBans) do
if tonumber(banEntry.UserId) == tonumber(victimId) then
table.remove(updatedBans, i)
Removed = true
break
end
end
local Succ, Msg = pcall(function()
DataCategory.set("PermanentBans", updatedBans)
end)
if not Succ and Msg then
addLog(sysTable.debugLogs, 'Funcs.permBan update, "unpban", Message: ' .. Msg or "Err")
end
end
else
remoteEvent:FireClient(Player, 'Message', 'Error', 'An error occurred while trying to "' .. Cmd .. '"' .. '\n' .. Msg)
return
end
if Removed then
remoteEvent:FireClient(Player, 'Hint', "Un-Permanently Banned", victimId .. ', ' .. victimName)
else
remoteEvent:FireClient(Player, 'Hint', "Error", "User was not already banned, or an unexpected error occurred.")
end
end)
if Msg then
addLog(sysTable.debugLogs, 'Funcs.permBan, "unpban", Message: ' .. Msg or "Err")
end
--elseif Cmd == "pbans" then
--local permanentBans = DataCategory.get("PermanentBans") or {}
--remoteEvent:FireClient(Player, 'PBans', permanentBans)
end
end
Any help on this is welcomed and appreciated!