So I made this script which when you enter a username into a box and then click 'BAN' it will ban the player. But I don't know how I would unban them? I am making an Admin GUI and I want a Button to unban then when I put in there username.

The first ban script

local BanData = game:GetService("DataStoreService"):GetDataStore("SaveBan")

game.Players.PlayerAdded:Connect(function(player)
	local Banned = Instance.new("BoolValue", player)
	Banned.Name = "Banned"
	
	local key = "Banned".."---"..player.UserId
	local SavedBan = nil
	
	pcall(function()
		SavedBan = BanData:GetAsync(key)
	end)
	
	if SavedBan ~= nil then
		Banned.Value = SavedBan
		if Banned.Value == true then
			player:Kick("Banned")
		end
	end
	
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	local Key = "Banned".."---"..player.UserId
	pcall(function()
		BanData:SetAsync(Key, player.Banned.Value)
	end)
end)

The second ban script

script.BanEvent.OnServerInvoke = function(player, PlayerName)
	if game.Players:FindFirstChild(PlayerName) then
		game.Players:FindFirstChild(PlayerName).Banned.Value = true
		game.Players:FindFirstChild(PlayerName):Kick("Banned")
	end
end

And the last ban script

script.Parent.MouseButton1Click:Connect(function()
	if game.Players:FindFirstChild(script.Parent.Parent.Parent.middlebar.user.Text)then
		local PlayerName = script.Parent.Parent.Parent.middlebar.user.Text
		game.Workspace.Events.BanEvent:InvokeServer(PlayerName)
	end
end)

How would I unban someone who is in a DataStore?

1 comment

0

Set their key data to false, or the opposite of whatever condition is passed to confirm the ban