Unban event won't unban individual

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.

Does your LocalScript still not work?

Local script hasn’t been working for the unban, but it works for the ban

Use this as the unban server script:

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 ~= v then
			continue
		end
		
		TempBanPlayerDataStore:RemoveAsync(v)
	end
end)

But, It’s not gonna work if the FireServer script won’t work.

What’s the LocalScript parented to?

The local script is parented to the frame.

Weird, it should work then, I’m guessing UNBAN is a button but I don’t know why it wouldn’t fire, any errors?

No errors at all when I press it, nor any when I connect.

Can I see how it is structured in the explorer?

1 Like

This is also completely wrong, because GetAsync:
“This function returns the latest value of the provided key and a [DataStoreKeyInfo] […] instance. If the key does not exist or if the latest version has been marked as deleted, both return values will be nil.”
That means running :GetAsync() without a key will instantly result in nil.
You will need to run :ListKeysAsync() but this is a bit more complicated. Heres an article to that if you want to stick on that method: How To Get All the data saved inside a datastore

But coming back to your problem, try it like that with using the Player Names as key:

CLIENT:
script.Parent.UNBAN.MouseButton1Click:Connect(function()
    print("Clicked") --To detect if the Button is working
    task.wait(1) --To make sure Client is loaded when the Event fires, sth thats a problem
	game.ReplicatedStorage.UnBan:FireServer(script.Parent.NameTextBox.Text)
end)

--SERVER:
game.ReplicatedStorage.UnBan.OnServerEvent:Connect(function(player, PlayerNameTextBox, ReasonTextBox)
	local DataStoreService = game:GetService("DataStoreService")
	local TempBanPlayerDataStore = DataStoreService:GetDataStore("TemporaryBanPlayerData")
	local PermBanPlayerDataStore = DataStoreService:GetDataStore("PermanentBanPlayerData")

	TempBanPlayerDataStore:RemoveAsync(PlayerNameTextBox)	
end)

Maybe that will do it.

So, it’s showing the “Clicked” for the print.

The server script isnt doing anything though. I’ve tried adding prints, yet nothing.

So you did make a print also above local DataStoreService = game:GetService(“DataStoreService”) and nothing came out? Super weird, I will go search a bit about this and write later more.

Ok so I have 2 more ideas.

  1. Please add a task.wait(1) above the :Connect() Event in the Server to make sure that the RemoteEvent has loaded when this line is getting read or make the RemoteEvent a variable and use :WaitForChild()
--SERVER:
print("Script is working")
local event = game:GetService("ReplicatedStorage"):WaitForChild("UnBan")
print("Got RemoteEvent")

event.OnServerEvent:Connect(function(player, PlayerNameTextBox, ReasonTextBox)
    print("Fired!!!")
	local DataStoreService = game:GetService("DataStoreService")
	local TempBanPlayerDataStore = DataStoreService:GetDataStore("TemporaryBanPlayerData")
	local PermBanPlayerDataStore = DataStoreService:GetDataStore("PermanentBanPlayerData")

	TempBanPlayerDataStore:RemoveAsync(PlayerNameTextBox)
    print("Removed Async")
end)
1 Like

Thank you so very much! It worked!

Your welcome! For more explanation, your problem was that the Event got fired before the Server loaded the RemoteEvent so he also couldnt fetch it.
Have a good day!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.