How can I create a ban/unban system using DataStore2?

Hello, people! Pretty simple question but how could I make a ban and unban system using DataStore2? I’m really confused on how to do it. I’ve tried multiple ways but couldn’t find a way to do it. Thanks for any type of help!

Code so far

--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

--// ReplicaedStorage Variables
local BanRE = ReplicatedStorage:WaitForChild("BanRE")
local DataStore2 = require(ReplicatedStorage:WaitForChild("MainModule"))

--// Other Variables
local BanGui = script:WaitForChild("BanGui")
local Mods = {
	1433248963;
}

--// Main
DataStore2.Combine("DATA", "BanDataStore")

local function OnPlayerAdded(LocalPlayer)
	local BanDataStore = DataStore2("BanDataStore", LocalPlayer)
	
	local IsBanned = Instance.new("BoolValue")
	IsBanned.Name = "IsBanned"
	IsBanned.Parent = LocalPlayer
	
	for _, v in pairs(Mods) do
		if LocalPlayer.UserId == v then
			BanGui:Clone().Parent = LocalPlayer:WaitForChild("PlayerGui")
		end
	end
	
	-- Don't know what to do after this part
end

Players.PlayerAdded:Connect(OnPlayerAdded)

for _, v in pairs(Players:GetPlayers()) do
	OnPlayerAdded(v)
end

Why not just use the normal DataStore system? DataStore v2 includes larger data limits (4mb, aka 4 million bytes), as well as data versioning.

There aren’t many reasons that I can think of to use DataStore2 anymore unless you don’t feel like converting your system back. But maybe that’s just me, I haven’t messed with it much.

1 Like

I’m not talking about the Datastore v2. I’m talking about the DataStore2 module.

I know, please reread what I wrote.

Oh sorry, I didn’t understand it before.

I don’t understand too much about DataStore. I did try with normal DataStore and it worked. But since DataStore2 is a bit more better than normal datastore I thought to make my ban system with DataStore2. So, thank you for explaining. (I made this post because I don’t understand a lot about Datastore so.)

By the way, I’ve a question. When I’m unbanning a player, should I just use like BanDataStore:RemoveAsync(id)
Something like this?

If you’re using a regular DataStore system, you can just use one array for the banlist, then you can use either SetAsync or UpdateAsync.

You can read more here:
Data Stores

1 Like

Okay, thank you so much for the help :grin:

1 Like