Unban event won't unban individual

I’m currently making a staff panel for my upcoming game, and there’s an unban feature for it, along with a ban and kick feature. The kick and ban feature work perfectly fine, as I know of; however, unbanning the individual is the problem now. I’ve attempted to unban a player, and it hasn’t worked. I used remote events for this.

If anyone has any potential solutions, please do let me know.

game.ReplicatedStorage.UnBan.OnServerEvent:Connect(function(player, PlayerNameTextBox, ReasonTextBox)
	local DataStoreService = game:GetService("DataStoreService")
	local TempBanPlayerDataStore = DataStoreService:GetDataStore("TemporaryBanPlayerData")
	local PermBanPlayerDataStore = DataStoreService:GetDataStore("PermanentBanPlayerData")
	
	
	-- Assume PlayerNameTextBox contains the name of the player to unban
	for _,Players in pairs(game.Players:GetPlayers()) do
		if Players.Name == PlayerNameTextBox then
			TempBanPlayerDataStore:RemoveAsync(Players)
		end
	end
end)
4 Likes

Dont check if the players in the game, if they are banned they wont be in the game, instead just do

game.ReplicatedStorage.UnBan.OnServerEvent:Connect(function(player, PlayerNameTextBox, ReasonTextBox)
	local DataStoreService = game:GetService("DataStoreService")
	local TempBanPlayerDataStore = DataStoreService:GetDataStore("TemporaryBanPlayerData")
	local PermBanPlayerDataStore = DataStoreService:GetDataStore("PermanentBanPlayerData")
	
	-- Assume PlayerNameTextBox contains the name of the player to unban
	TempBanPlayerDataStore:RemoveAsync(Players)
end)
2 Likes

Wouldn’t that just remove everyone?

Also, “Players” won’t work due to the fact it was called in the for _,Players

Why did you did this for loop? If a player is banned, he cant be ingame and so you wont get anything for the value “Players”. Ig you can just do
TempBanPlayerDataStore:RemoveAsync(PlayerNameTextBox)
Or do you have User IDs as Key?

3 Likes

For loop works in the ban part still. No User ID’s are logged though; however, I can change it if needed.

1 Like

If you only log the username, just remove from the username from the banned players data store.

1 Like

This code should work as intended.

game.ReplicatedStorage.UnBan.OnServerEvent:Connect(function(player, PlayerNameTextBox, ReasonTextBox)
	local DataStoreService = game:GetService("DataStoreService")
	local TempBanPlayerDataStore = DataStoreService:GetDataStore("TemporaryBanPlayerData")
	local PermBanPlayerDataStore = DataStoreService:GetDataStore("PermanentBanPlayerData")
	
	for i,v in pairs(TempBanDataStore:GetAsync()) do
		if PlayerNameTextBox.Text ~= v then
			continue
		end
		
		TempBanPlayerDataStore:RemoveAsync(v)
	end
end)

Theoretically, say I were to use UserID and Player name?, what would I do then?

Then the following code should do what you want:

game.ReplicatedStorage.UnBan.OnServerEvent:Connect(function(player, PlayerNameTextBox, ReasonTextBox)
	local DataStoreService = game:GetService("DataStoreService")
	local TempBanPlayerDataStore = DataStoreService:GetDataStore("TemporaryBanPlayerData")
	local PermBanPlayerDataStore = DataStoreService:GetDataStore("PermanentBanPlayerData")
	
	for i,v in pairs(TempBanDataStore:GetAsync()) do
		if tonumber(PlayerNameTextBox.Text) ~= v then -- Use tonumber to turn the string into a number (in case you saved the user ID as a number)
			continue
		end
		
		TempBanPlayerDataStore:RemoveAsync(v)
	end
end)
2 Likes

This script didn’t work and I’m unsure why. Should I put some prints or warn’s in at all? if so, where?

1 Like

Hm, I’m guessing you save the data store as a table, right?

1 Like

I’m unsure to be quite honest. I just did a simple :GetDataStore(“TemporaryBanData”) and what not, I know the datastore works as I have a datastore editor that show’s it.

Oh, hold on, I believe I made a mistake in my script when writing the name of the datastore:

ID Unban

game.ReplicatedStorage.UnBan.OnServerEvent:Connect(function(player, PlayerNameTextBox, ReasonTextBox)
	local DataStoreService = game:GetService("DataStoreService")
	local TempBanPlayerDataStore = DataStoreService:GetDataStore("TemporaryBanPlayerData")
	local PermBanPlayerDataStore = DataStoreService:GetDataStore("PermanentBanPlayerData")
	
	for i,v in pairs(TempBanPlayerDataStore:GetAsync()) do
		if tonumber(PlayerNameTextBox.Text) ~= v then -- Use tonumber to turn the string into a number (in case you saved the user ID as a number)
			continue
		end
		
		TempBanPlayerDataStore:RemoveAsync(v)
	end
end)

Username Unban

game.ReplicatedStorage.UnBan.OnServerEvent:Connect(function(player, PlayerNameTextBox, ReasonTextBox)
	local DataStoreService = game:GetService("DataStoreService")
	local TempBanPlayerDataStore = DataStoreService:GetDataStore("TemporaryBanPlayerData")
	local PermBanPlayerDataStore = DataStoreService:GetDataStore("PermanentBanPlayerData")
	
	for i,v in pairs(TempBanPlayerDataStore:GetAsync()) do
		if PlayerNameTextBox.Text ~= v then
			continue
		end
		
		TempBanPlayerDataStore:RemoveAsync(v)
	end
end)
1 Like

This script should work, my bad.

1 Like

This one doesn’t show you removed anything.

1 Like

Nevermind, I saw what changed.

I think I may need to add in some prints, it still isn’t working. It could be something I did that’s making it not work, but I may try and put in some prints to find out. One moment.

Okay, so I’ve found an error then on my end. For some reason, the FireServer isn’t connecting to the unban event whatsoever. I’ve made sure everything is correct, unless I’m missing something of course.

I’ve tried changing the name of the textboxes and stuff.

Fireserver script:


local gui = script.Parent.Parent.Parent.StaffPanel
local banGui = gui:WaitForChild("Unban")
local playerNameTextBox = banGui:WaitForChild("PlayerNameTextBox")

local reasonTextBox = banGui:WaitForChild("ReasonTextBox")
local daysTextBox = banGui:WaitForChild("DaysTextBox")



script.Parent.UNBAN.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.UnBan:FireServer(script.Parent.NameTextBox.Text)
end)

Then the onserverevent is shown in the previous script.

Alright then test the new server script I made, lmk if it works.

The thing is, mine still doesn’t work unfortunately. I don’t know what I did.