Hello, I’ve recently used tables to store data such as if a user has a warning under there name. What if I want to clear the warnings off an offline user? The table saves and loads using the userId then a key that I can use to reset data. I was wondering if it’d be possible to get the userId of a user who is offline based on the name and then load in there data in the table to then remove the warnings or bans.
Hm, the userId from name Async seems to work. Although when firing the client (for a check) it always returns nil. Even when I make sure it says return true. I added prints to debug and everything seems like it should work fine. The client has return true… the server prints that its nil. I assume this isn’t to do with the userId but is there a reason for this?
Also, would this work if the user is offline/not in game?
While attempting to do your idea it didn’t seem to work.
_G.ClearPunishments = function(plr,target)
pcall(function()
print(game:GetService("Players"):GetUserIdFromNameAsync(target))
if game:GetService("Players"):FindFirstChild(target) then else
Punishments[target] = PunishmentsStorage:GetAsync(game:GetService("Players"):GetUserIdFromNameAsync(target)..punishmentKey)
end
Punishments[target]['Warnings'] = 0
Punishments[target]['Banned'] = false
Punishments[target]['BanReason'] = "None"
PunishmentsStorage:SetAsync(game:GetService("Players"):GetUserIdFromNameAsync(target)..punishmentKey, Punishments[target])
if game:GetService("Players"):FindFirstChild(target) then else
Punishments[target] = nil
end
end)
end
Something is bothering me about this code, in other news. Did you create a table for the user, or is a table saved to the datastore? If not, you can’t start assigning keys and values out of the blue.
Punishments[target] = {}
Punishments[target]["Warnings"] = blah whatever
GetAsync whatever whatever
-> Should return a table