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)
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)
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?
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)
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)
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)
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.