Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i unban a player if they werent in the game?

Asked by
Zrxiis 26
7 years ago

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.

01local admins = {
02    "FangBlade16";
03}
04 
05local banlist = game:GetService("DataStoreService"):GetDataStore("BanList")
06 
07game.Players.PlayerAdded:connect(function(player)
08    local playerId = player.UserId
09    local check = banlist:GetAsync(playerId)
10    if check == nil then
11        banlist:SetAsync(playerId,"Clear")
12    elseif check == "Banned" then
13        player:Kick("You are banned from this game")
14    elseif check == "Clear" then
15        print("You are clear!")
View all 37 lines...

1 answer

Log in to vote
1
Answered by 7 years ago
01...
02 
03player.Chatted:connect(function(msg)
04    if string.sub(msg, 1, 6) == ":unban" then
05        local playerName = string.sub(msg, 8)
06        -- first look for the player in the game
07        for _, player in pairs(game.Players:GetPlayers()) do
08            if player.Name == playerName then
09                banlist:SetAsync(player.UserId, "Clear")
10                return
11            end
12        end
13        -- if we get to this line, it means the player isn't in this game
14        local success, pardonedId = pcall(function()
15            return game.Players:GetUserIdFromNameAsync(playerName)
View all 35 lines...
0
Oops I didn't realize that `player` was 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 the `player` variable from line 24 to the end to something else, like `suspect` or `troublemaker` WillieTehWierdo200 966 — 7y
0
Thank you it worked. Zrxiis 26 — 7y
Ad

Answer this question