A very weird thing, this script stopped working, I can't see a reason, I know where the error is but not why it happends, the table is not nil but still when I use for i,v in pairs(table) it won't work. (It doesn't print out the values)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local banEvent = ReplicatedStorage:WaitForChild("AddBan")

local unbanEvent = ReplicatedStorage:WaitForChild("RemoveBan")
local getBans = ReplicatedStorage:WaitForChild("GetBans")

local DataVersion = 4
Attempt = 0

local DataStore = game:GetService("DataStoreService")
local BanlistSave = DataStore:GetDataStore("BLA_"..DataVersion)

unbanPlace = 0
found = false

banList = {}
globalKey = 1920 -- 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
local CSPD = workspace:WaitForChild('CanSavePlayerData')

notFound = false
unbannedPlrFound = false

function getBanList()	
	local banListNC = BanlistSave:GetAsync(globalKey) or nil
	banList = {''}
	for index, save in pairs(banListNC) do -- PROBLEM IS HERE. It doesn't print anything!
		print(save)
	end
	for index, save in pairs(banListNC) do
		table.insert(banList,save)
		print(save)
	end		
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
	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)
	
	if banList == nil then
		banList = {}
		table.insert(banList, TargettedPlayer)
		
		BanlistSave:SetAsync(globalKey, banList)
		
		warn('error in banlist, banlist appears to be nil!')
	else
		for index, bannedPLR in pairs(banList) do
			if TargettedPlayer == bannedPLR then
				warn(TargettedPlayer..' is already banned!')
				found = true
			end
		end
		if found == true then
			warn('can\'t ban player because he is already banned')
		else
			table.insert(banList, TargettedPlayer)					    -- Adds name to datastore table
			print('succesfully stored values')
		end
		found = false
	end
	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
	
	CSPD.Value = false
	wait(5)
	warn('should be saving')
	BanlistSave:SetAsync(globalKey, banList)
	wait(2)
	CSPD.Value = true
		
end)

unbanEvent.OnServerEvent:connect(function(player, TargettedPlayer)  -- Unbans player on remote event
	warn('connection remote event unban')
	warn('player '..player.Name..' is trying to unban player '..TargettedPlayer)
	
	unbanPlace = 0
	for index, bannedPlr in pairs(banList) do
		if bannedPlr ~= TargettedPlayer then      -- Testing the place of the name
			unbanPlace = unbanPlace + 1
		else
			break
		end
	end
	
	unbanPlace = unbanPlace + 1
	
	CSPD.Value = false
	wait(5)
	
	print(unbanPlace)
	print(banList[unbanPlace])
	
	table.remove(banList, unbanPlace)                                -- Finally remove the player from the table
	unbanPlace = 0
	
	warn('should be saving')
	BanlistSave:SetAsync(globalKey, banList)	                     -- Saves it (we don't want it to ban him again xD)
	
	CSPD.Value = true
	end)

function getBans.OnServerInvoke(player)                              -- Local script requesting banlist
	warn('sending banlist')
	print(banList)
	return banList
end


while wait(20) do												    -- Updates list every 20 seconds
	getBanList()
end

2 comments

0

btw, I made this script myself lol, the comments are there because the script is to huge for me to take a look at when there is a problem.

0

I know this wont help but dont you use ipairs when declaring a table?