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.
I'm really out of time, wrote this basic script which I am 100% will help, but basically, use only ONE key for the banned players, and also some code shortening using table.find
:
local dss = game:GetService("DataStoreService") local http = game:GetService("HttpService") local banStore = dss:GetDataStore("banStore") local banned = {} game.Players.PlayerAdded:Connect(function(player) pcall(function() banned = http:JSONDecode(banStore:GetAsync("banned")) end) if banned then if table.find(banned,player.Name) then player:Kick("banned lol") end end end) game.Players.PlayerRemoving:Connect(function(player) banStore:SetAsync("banned",http:JSONEncode(banned)) end) local function ban(player) table.insert(banned,#banned+1,player.Name) end
Hope this helped! (even though i didn't really explain anything) Edit: added a function so you know how to add banned players.