Im trying to make a script so i can ban, kick, and unban players. But I'm not able to unban if the players arent in the game.
local admins = {
"FangBlade16";
}
local banlist = game:GetService("DataStoreService"):GetDataStore("BanList")
game.Players.PlayerAdded:connect(function(player)
local playerId = player.UserId
local check = banlist:GetAsync(playerId)
if check == nil then
banlist:SetAsync(playerId,"Clear")
elseif check == "Banned" then
player:Kick("You are banned from this game")
elseif check == "Clear" then
print("You are clear!")
end
for i, admins in ipairs(admins) do
if player.Name == admins then
player.Chatted:connect(function(msg)
for i,players in ipairs(game.Players:GetChildren()) do
if msg == ":kick "..players.Name then
players:Kick("You have been kicked by: "..player.Name)
elseif msg == ":ban "..players.Name then
banlist:SetAsync(players.UserId,"Banned")
players:Kick("You have been banned by: "..player.Name)
--This part below wont work.
elseif msg == ":unban "..players.Name then
local pardonedId = game.Players:GetUserIdFromNameAsync(players.Name)
banlist:SetAsync(pardonedId,"Clear")
end
end
end)
end
end
end)

2 comments
Oops I didn't realize that
playerwas already defined as the chatting player, so it will be overwritten in the second half of your script block and the kick messages will tell the kicked players that they were kicked by themselves! If you want to fix this, rename theplayervariable from line 24 to the end to something else, likesuspectortroublemakerThank you it worked.