Unban Not Working

Hey there,

So I am working on an admin panel for my game. Below is the whole server script for the panel. Everything works fine, but the “Unban” action is not working. I am getting the “Event Fired2” message in the output telling me that it is getting to that point of the script, but not removing the player from the datastore.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DatastoreService = game:GetService("DataStoreService")

local EventsFolder = ReplicatedStorage.StaffPanelEvents
local ActionEvent = EventsFolder.AdminActions
local GetBanListEvent = EventsFolder.GetBanList

local BanDS = DatastoreService:GetDataStore("FullBanList")
local key = "BanList"

ActionEvent.OnServerEvent:Connect(function(adminplr,action,playername,content,content2)
	local plrid = nil
	local plr = nil
	
	print("Event fired1")
	
	if playername == nil then
	else
		plrid = game.Players:GetUserIdFromNameAsync(playername)
		plr = game.Players:GetPlayerByUserId(plrid)
	end
	
	if action == "Kick" then
		plr:Kick("You have been kicked by the staff member ".. adminplr.Name ..".")
	end
	
	if action == "TP" then
		adminplr.Character.HumanoidRootPart.CFrame = plr.Character.HumanoidRootPart.CFrame + Vector3.new(0,2,1)
	end
	
	if action == "Bring" then
		plr.Character.HumanoidRootPart.CFrame = adminplr.Character.HumanoidRootPart.CFrame + Vector3.new(0,2,1)
	end
	
	if action == "Kill" then
		plr.Character.Humanoid.Health = 0
	end
	
	if action == "Unban" then
		print("Event fired2")
		
		BanDS:UpdateAsync(key, function(old)
			old=old or {}
			
			print("Event fired")
			
			table.remove(old,plrid)
			
			return old
		end)
	end
	
	if action == "Message" then
		local m = Instance.new("Hint",game.Workspace)
		m.Name = "AdminMessage"
		m.Text = content
		
		if tonumber(content2) then
			wait(tonumber(content2))
			m:Destroy()
		else
			wait(3)
			m:Destroy()
		end
	end
	
	if action == "Ban" then
		BanDS:UpdateAsync(key, function(old)
			old=old or {}
			old[plr.UserId]=true
			return old
		end)
		
		plr:Kick("You are banned from this experience. You may appeal this action by contacting a staff member via our Discord.")
		
		local data = BanDS:GetAsync(key)
		local banlist = {}

		for i,v in pairs(data) do
			local playerName = game.Players:GetNameFromUserIdAsync(i)
			print(playerName)

			table.insert(banlist,playerName)
		end

		GetBanListEvent:FireAllClients(banlist)
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	local data = BanDS:GetAsync(key)
	local banlist = {}
	
	for i,v in pairs(data) do
		local playerName = game.Players:GetNameFromUserIdAsync(i)
		print(playerName)
		
		table.insert(banlist,playerName)
		
		if playerName == plr.Name then
			plr:Kick("You are banned from this experience. You may appeal this action by contacting a staff member via our Discord.")
		end
	end
	
	GetBanListEvent:FireAllClients(banlist)
end)

Any help would be greatly appreciated!
Thank you,

do you get the Event Fired after the BanDS:UpdateAsync(key, function(old)

Sorry I don’t understand what you mean.

In that section of your code you create an inline function that is called by the DataStore and in it you have a print(“Event fired”) so I was asking if that print had run so we can confirm the DataStore process worked.
If is does can you comment out the old = old or {} line and see what happens.

The print statement did run, yes.

ok so does it work if you use RemoveAsync instead of UpdateAsync?

Your operations contradict each other. To ban a user, you write their UserId as a key in a dictionary, yet to unban a user, you attempt to remove them as an element of an array.

You have to remain consistent with your data structure:

local function UnbanTransform(BanDictionary)
    if BanDictionary then
        BanDictionary[Player.UserId] = nil
    end

    return BanDictionary
end

FYI, I recommend storing your commands in a dictionary too. That will improve the readability and scalability of your system.