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

Making A Table That Stores Banned People?

Asked by
fff054 51
4 years ago

So, I'm Making A Ban Hammer And I Want To Add People To A Table In Which They'll Be Kicked Out. I'm Trying To Store The Table In Datastore2, But I Have No Clue Of How To Do It. Also, I Need To Update The Table Every Time Someone Gets Banned. I Know It Sound Kinda Simple, But I'm Really Struggling With It. I've Tried With Data Store (The One That Roblox Brings) Because I Thought It'll Be Easier And Now I Know It Wasn't.

Here Is The Last Version Of My Code, In Which I Didn't Succeed :/

--// Ban Data Store \\--
local BannedList = {410710393}

local RealBannedList = {} 

pcall(function()
    if game:GetService('DataStoreService'):GetDataStore('BannedPeople'):GetAsync('ABannedList') then
        return 
    else
    local Data = game:GetService('DataStoreService'):GetDataStore('BannedPeople'):SetAsync('ABannedList',RealBannedList)
    local Table = game:GetService('DataStoreService'):GetDataStore('BannedPeople'):GetAsync('ABannedList')
    end
end)

local Table = game:GetService('DataStoreService'):GetDataStore('BannedPeople'):GetAsync('ABannedList')

game.Players.PlayerAdded:Connect(function(plr)
    for i = 1, #BannedList do
        if plr.UserId == BannedList[i] then
            plr:Kick("Banned Forever.")
        end
    end
end)

game.Players.PlayerAdded:Connect(function(plr)
    for i = 1, #Table do
        print(Table[i])
        if plr.UserId == Table[i] then
            plr:Kick("Banned Forever.")
        end
    end
end)

game.ReplicatedStorage.DevelopersRemotes.BanRemote.OnServerEvent:Connect(function(plr)
    table.insert(RealBannedList, plr.UserId)
    game:GetService("DataStoreService"):GetDataStore('BannedPeople'):SetAsync('ABannedList', RealBannedList)
end)

0
From what I've heard and done, using the ROBLOX DataStore to store tables is easier than DataStore2. killerbrenden 1537 — 4y
0
Ik, but it still doesn't work :/ fff054 51 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

I got my own anti-cheat in a project of mine and I utilize DSS as well. I use two seperate scripts to achieve this, but you could most likely use one.

--DataStorage Script
local DSS = game:GetService("DataStoreService")
local MDS = DSS:GetDataStore("MDS")

game.Players.PlayerAdded:Connect(function(plr)
    local data = Instance.new("Folder")
    data.Name = "PlayerData"
    data.Parent = plr

    local banned = Instance.new("BoolValue")
    banned.Name = "isBanned"
    banned.Parent = data

    local money = Instance.new("IntValue")
    money.Name = "Cash Money"
    money.Parent = data

    local Banneddata
    local Moneydata

    local success, errormsg = pcall(function()
        Banneddata = MDS:GetAsync(plr.UserId.. "-isBanned")
        Moneydata = MDS:GetAsync(plr.UserId.. "-Money")
    end)

    if success then
        banned.Value = Banneddata
        money.Value = Moneydata
        if banned.Value == true then
            plr:Kick("You're not welcome here.")
        end
    else
        print("There was an error while recovering ".. plr.Name.. "'s data...")
        warn(errormsg)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)

    local success, errormsg = pcall(function()
        MDS:SetAsync(plr.UserId.."-isBanned", plr.PlayerData.isBanned.Value)
        MDS:SetAsync(plr.UserId.. "-Money", plr.PlayerData["Cash Money"].Value)
    end)

    if success then
        print(plr.Name.. "'s data was saved.")
    else
        print(plr.Name.. "'s data was not saved due to an error.")
        warn(errormsg)
    end

end)
--Second script.
local Banned = {}
local Favorites = {1348670747,}
game.Players.PlayerAdded:Connect(function(plr)
    local PlayerData = plr:WaitForChild("PlayerData")
    for i, b in ipairs(Banned) do
        if b == plr.UserId then
            plr:Kick("You're not welcome here.")
            print(plr.Name.. " was kicked.")
        end
    end
    for i, b in ipairs(Favorites) do
        if b == plr.UserId then
            print(plr.Name.. ".")
        end
    end
    if plr.PlayerData.isBanned.Value == true then
        plr:Kick("You're not welcome here.")
    end
end)
--[[
    Temporary Ban List
    -
--]]

So how does it work? Whenever a play joins the game, a folder called "PlayerData" is inserted into the instance, where it keeps track of their banned state, and money in my case. If my anti-cheat catches a player, it ticks off their 'banned' bool as true, then kicking them. If they dare to rejoin, it checks if they're banned and if so, it kicks them. In your case, you can make it so that when you hit the player with your ban hammer, it gets the player from the character, turns the banned bool to true, and kick them. Edit: Remember that I used DataStoreService, but you could probably use DS2.

Ad

Answer this question