It saves it as you say but you do not load it from the cloud, by that i mean KickLogLocation is unused and KickLogs is empty, which means every time you save it you save empty table with you new value, but when rejoining you are not using the saved data. In your case KickLogLocation is never used, not once.
Of course you can fix that by setting KickLogs to loaded save from the cloud
local KickLogs = MasterSettings:GetAsync("Moderation/logs/KickLogs/");
AdminEvents.KickPlayer.OnServerEvent:connect(function(player, playerToKick, reason)
table.insert(KickLogs, "Test")
print(KickLogs)
wait(1)
MasterSettings:SetAsync("Moderation/logs/KickLogs/", KickLogs);
end)
That should fix that because now you actually restore the data, the problem is tho that it's ugly, for me at least, that's why you use UpdateAsync! It's similar to SetAsync but if you have 2 admins on different servers, you are going to lose data because your table does not share between servers so both of ya gamers are going to save moderation claims into different tables and then saving them, overriding what the other admin on the other server saves.
UpdateAsync has cool feature, it returns previous data if any found, with that in your case you are always going to add new kick log to the newest table from the cloud! In your case it would look like this
local KickLogs = MasterSettings:GetAsync("Moderation/logs/KickLogs/");
AdminEvents.KickPlayer.OnServerEvent:connect(function(player, playerToKick, reason)
print(KickLogs)
local function OnUpdate(OldData)
local NewData = OldData or {};
table.insert(NewData, "Test");
return NewData;
end
MasterSettings:UpdateAsync("Moderation/logs/KickLogs/", KickLogs, OnUpdate);
end)
Third argument of UpdateAsync is a function, this function returns the OldData which is previously saved data. Whatever the OnUpdate function returns will be saved into the cloud, if you return nil, nothing is going to be saved, by that i mean nothing will change, it wont' save nil.
You of course should be also using pcalls because in some cases if data store errors, your script will stop and your logs won't work, not a problem in your case because when server restarts nothing is going to get lost but in some cases it does actually lead to data loss.
I actually noticed one thing in your script, of course i am one of those people who does not care about exploiters but even i would create a simple check if player who is sending the remote is admin!!!!!!!!! Any exploiter can send this remote and the player is going to get kick logged which is not what you want!!!! Implement simple system like this
local Admins = {"kirda", "MegaSpaheggti"}
AdminEvents.KickPlayer.OnServerEvent:connect(function(player, playerToKick, reason)
if not (table.find(Admins, player.Name)) then
player:Kick("you exploit");
return;
end
print(KickLogs)
...
table.find will look if player.Name is found in the Admins table, if it was not found it will return nil which will pass the if statement and kick the exploiter!
###UpdateAsync
###pcall
###table.find
##Edit
Turns out i am blind, since UpdateAsync knows what you are going to save, you don't need second argument, change
MasterSettings:UpdateAsync("Moderation/logs/KickLogs/", KickLogs, OnUpdate);
to
MasterSettings:UpdateAsync("Moderation/logs/KickLogs/", OnUpdate);
It already knows that KickLogs table is going to be saved from OnUpdate return!!
1 comment
BTW: It saves MasterSettings:SetAsync("Moderation/logs/KickLogs/", "TEST");