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

Unbanning player with datastores?

Asked by 7 years ago
Edited 7 years ago

I need help with datastores. I figured out how to ban a player with datastores, but how would I unban that player? This below is how the ban works and how a person gets banned in-game. If the number is greater than 0, then the player is banned. How would I write code that would unban the player without the player being in the game?

_G["bandata"] = "byeskid"
local banstore = game:GetService("DataStoreService"):GetDataStore(_G.bandata)

function onPlayerEntered(player)
    local ban = banstore:GetAsync(player.userId .. "_ban")
    if ban and ban > 0 then
        player:Kick()
    end
end

--------BAN-PLAYER--------

function Ban()
    local name = script.Parent.Player.Text
    if name and not script.Parent.Parent:FindFirstChild("Pass") then
        local banned = game.Players:FindFirstChild(name)
        if banned then
            banstore:SetAsync(banned.userId .. "_ban", 3)
            banned:Kick()
        end
        script.Parent.Player.Text = " "
    end
end
script.Parent.Ban.MouseButton1Click:connect(Ban)

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

"If the number is greater than 0, then the player is banned."

So, you can simply save their value as 0 again.

function UnBan()
    local name = script.Parent.Player.Text
    name = game.Players:GetUserIdFromNameAsync(name)
    if name and not script.Parent.Parent:FindFirstChild("Pass") then
        banstore:SetAsync(name.."_ban",0)
    end
end

script.Parent.UnBan.MouseButton1Click:Connect(UnBan)
1
Addendum, if you want to be able to use the name you can use http://wiki.roblox.com/index.php?title=API:Class/Players/GetUserIdFromNameAsync Pyrondon 2089 — 7y
0
Nice tip ;D Goulstem 8144 — 7y
Ad

Answer this question