I don't know what the problem is, this is the error: Workspace.AdmindCommands.Ban:42: bad argument #1 to 'insert' (table expected, got nil)
This is the code (serverscript), this is linked to a local. I made a lot off comments, mostly to help myself to navigate trough this too long script, I added a comment too on places that give an error
I want to insert the name of the player in that table and then save it.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local banEvent = ReplicatedStorage:WaitForChild("AddBan")
local DataStore = game:GetService("DataStoreService")
local BanlistSave = DataStore:GetDataStore("BanlistDataStore")
banList = {}
globalKey = 1092 -- If you want to clear this datastore just change this value
unbanList = {} -- Add names to this list if you want them to be unbanned, load the server, then remove them
function getBanList()
banList = BanlistSave:GetAsync(globalKey) -- Sets the table to the save file
end
if unbanList ~= nil then -- Checks if unbanlist is empty
getBanList()
for index, unban in pairs(unbanList) do
for index, ban in pairs(banList) do
if unban == ban then -- Checks if player is actually banned
table.remove(banList,ban) -- If so, remove the player out of the table
end
end
end
end
game.Players.PlayerAdded:connect(function(plr) -- Player joined
getBanList() -- Refreshed the banlist
wait(1)
for index, bannedPlr in pairs(banList) do -- Checks if the name of the player is the same as a name out of the banlist
print(bannedPlr)
if plr.Name == bannedPlr then
plr:Kick("Your banned. If you think this is an error please contact one of our admins!") -- Kick if neccesary
end
end
end)
banEvent.OnServerEvent:connect(function(player, TargettedPlayer) -- Bans player on remote event
warn('conection remote event ban')
print("banning "..TargettedPlayer)
table.insert(banList, TargettedPlayer) -- Adds name to datastore table PROBLEM IS HERE!!!!!
for index, gamePlayer in pairs(game.Players:GetPlayers()) do
if gamePlayer.Name == TargettedPlayer then
gamePlayer:Kick("admin "..player.Name.." has banned you. Believe this is an error? Message one of our admins!") -- Kicks player
end
end
BanlistSave:SetAsync(globalKey, banList) -- Saves the table
end)
while wait(1) do -- Updates list every second
getBanList()
end

3 comments
Does the script print nil on "TargettedPlayer"? If so, that's probably why you're getting that error.
Nope, it isn't nil
it prints Player2 (when I use it on player2)