Hey all! So I have been trying to make an unban command for the past few days but I think I am slightly “DUMB”. I will show my permanent ban script and the unban script. Both are used via command depending on your rank in a group. If you know the issue can you please tell me? Or can anyone tell me any fixes that I can do? Thanks! (the permanent ban command works, it is just the unban that doesn’t work)
Permanent Ban Script:
-- Command Format - :pban username reason (Every Argument Necessary)
-- Change Settings Here:
local groupId = 15257297
local minimumRankToUseCommand = 17
-------------------------------------
local dss = game:GetService("DataStoreService")
local banDS = dss:GetDataStore("BanData")
game.Players.PlayerAdded:Connect(function(plr)
local result = nil
local success, err = pcall(function()
result = banDS:GetAsync(plr.UserId .. "-BanData")
end)
if result then
plr:Kick("\nBanned permanently")
else
pcall(function()
banDS:SetAsync(plr.UserId .. "-BanData", {false; nil})
end)
end
if plr:GetRankInGroup(groupId) >= minimumRankToUseCommand then
plr.Chatted:Connect(function(msg)
local splitMsg = string.split(msg, " ")
if splitMsg[1]:lower() == ":pban" then
local banCmd = splitMsg[1]
local plrName = splitMsg[2]
local reason = string.sub(msg, #splitMsg[1] + #splitMsg[2] + 2, #msg) or "Reason unavailable."
local plrId = game.Players:GetUserIdFromNameAsync(plrName)
if plrId then
pcall(function()
banDS:SetAsync(plrId .. "-BanData", 1)
end)
if game.Players:FindFirstChild(plrName) then
game.Players[plrName]:Kick(reason .. "\nBanned permanently")
end
end
end
end)
end
end)
Unban Script:
-- Command Format - :unban username (Every Argument Necessary)
-- Change Settings Here:
local groupId = 15257297
local minimumRankToUseCommand = 13
-------------------------------------
local players = game:GetService("Players")
local dss = game:GetService("DataStoreService")
local banDS = dss:GetDataStore("BanData")
game.Players.PlayerAdded:Connect(function(plr)
if plr:GetRankInGroup(groupId) >= minimumRankToUseCommand then
plr.Chatted:Connect(function(msg)
local splitMessage = msg:lower():split(" ")
if splitMessage[1] == ":unban" then
local plrToUnbanUserId = players:GetUserIdFromNameAsync(splitMessage[2])
pcall(function()
banDS:SetAsync(plrToUnbanUserId .. "-BanData", {false; nil})
end)
print("Unbanned Successfully!")
end
end)
end
end)