local DatastoreService = game:GetService("DataStoreService")
local ds = DatastoreService:GetDataStore("BanList")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event1 = ReplicatedStorage.AdminGui:WaitForChild("Ban")
local event2 = ReplicatedStorage.AdminGui:WaitForChild("Unban")
local Players = game:GetService("Players")
local bannedpeople = {}
ds:GetAsync(bannedpeople)
game.Players.PlayerAdded:Connect(function(plr)
if table.find(bannedpeople, plr.UserId) then
wait(0.2)
plr:Kick("You are permanently banned from the game.")
print("autoban")
end
end)
local function Banned(admin, username, reason)
local bannedplayer = Players:FindFirstChild(username)
if bannedplayer ~= nil then
game.Players:FindFirstChild(bannedplayer):Kick(reason)
table.insert(bannedpeople, bannedplayer.UserId)
ds:SetAsync(bannedpeople)
print("banned")
end
end
local function Unbanned(admin, username, reason)
local unbannedplayer = Players:FindFirstChild(username)
if unbannedplayer ~= nil then
if table.find(bannedpeople, unbannedplayer.UserId)then
table.remove(bannedpeople, table.find(bannedpeople, unbannedplayer.UserId))
ds:SetAsync(bannedpeople)
print("unbanned")
end
end
end
event1.OnServerEvent:Connect(Banned)
event2.OnServerEvent:Connect(Unbanned)
This question got edited, i wanna know if it's correct.
Please help me.

5 comments
what is the purpose of using jsonencode? why not just store the normal table information?
Datastores only accept numbers and strings, and JSONEncode converts tables to strings. Hence why. However, from what I know, some time in the past they made it so it automatically converted it to json strings if you attempted to save tables to a datastore, but I still do it for a habit.
Thanks, I was looking for this.
yeah i was wondering bc i save tables to datastores all the time, but i suppose converting them yourself might be more efficient
congrats a whole json encode decode system