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