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)
... player.Chatted:connect(function(msg) if string.sub(msg, 1, 6) == ":unban" then local playerName = string.sub(msg, 8) -- first look for the player in the game for _, player in pairs(game.Players:GetPlayers()) do if player.Name == playerName then banlist:SetAsync(player.UserId, "Clear") return end end -- if we get to this line, it means the player isn't in this game local success, pardonedId = pcall(function() return game.Players:GetUserIdFromNameAsync(playerName) end) if success then banlist:SetAsync(pardonedId, "Clear") else print("User '"..playerName.."' does not exist") end else -- this is your existing code for :kick and :ban for _, player in pairs(game.Players:GetPlayers()) do if msg == ":kick "..player.Name then player:Kick("You have been kicked by: "..player.Name) elseif msg == ":ban "..player.Name then banlist:SetAsync(player.UserId,"Banned") player:Kick("You have been banned by: "..player.Name) end end end end) ...