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

How do make a ban system for players that you ban?

Asked by 3 years ago

This is a script in a serverscriptservice

Nothing happens when i click myself and click ban button
```lua
local BannedPlayers = {}

local DataStoreService = game:GetService("DataStoreService")
local BanDataStore = DataStoreService:GetDataStore("BanDataStore")

--Function
local function BanPlayer(player,reason)
    local BanButton = game.StarterGui.AdminGui.MainFrame.BanButton
    local TimeBanned = BanButton.TimeBanned

    BanButton.MouseButton1Click:Connect(function()
        for i,v in pairs(BanButton.Parent.PlayersScrollList:GetChildren()) do
            if v:IsA("Frame") then
                if v.selected.Value == true then
                    local player = string.gsub(v.ActualName.Text,"@","")
                    if game.Players:FindFirstChild(player) then
                        if game.Players:FindFirstChild(player).UserId == 777304992 then
                            BanButton.Text = "Cannot ban owner."
                            wait(2)
                            BanButton.Text = "Ban"
                        else
                            table.insert(BannedPlayers,game.Players:FindFirstChild(player).UserId)
                            game.Players:FindFirstChild(player):Kick("You are temporarily banned")
                        end
                    end
                else
                    BanButton.Text = "No player selected,"
                    wait(2)
                    BanButton.Text = "Ban"
                end
            else
                v.Archivable = false
                wait()
                v.Archivable = true
            end
        end
    end)
end

game.Players.PlayerAdded:Connect(function(plr)
    local plrUserId = plr.UserId

    if BannedPlayers[plrUserId] then
        plr:Kick("You are temporarily banned.")
    end

    local banned
    local success,errorMsg = pcall(function()
        banned = BanDataStore:GetAsync(plrUserId)
    end)

    if banned == true then 
        plr:Kick("You are temporarily banned.")
    end


end)```

Answer this question