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

Is it possible to make a Ban Function using Data Store?

Asked by 7 years ago
Edited 7 years ago

I am trying to fix this problem but I get so confused please help me. If it is possible please Help.

0
yes Shawnyg 4330 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

Yes it is possible

Here is an example:

--Server Script
local datastore = game:GetService("DataStoreService"):GetDataStore("Bans")

game.Players.PlayerAdded:connect(function(plr)
    local key = "user_" .. plr.UserId

    local banned = Instance.new("BoolValue", plr)
    banned.Value = datastore:GetAsync(key) or false
    banned.Name = "Banned"

    if banned.Value == true then
        plr:Kick("You have been banned!")
    end


    banned.Changed:connect(function()
        datastore:SetAsync(key, banned.Value)

        if banned.Value == true then
            plr:Kick("You have been banned!")
        end
    end)
end)
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

how can the code you posted be made to ban players if they try to use commands?

Answer this question