--Ban
if string.sub(msg,1,4) == "!ban" then
local player = (string.sub(msg,6))
local findplr = game.Players:FindFirstChild(player)
if findplr then
print(findplr)
if findplr.Name == "itz_rennox" or plr.Name == "theprofficer" then --Owner
else
local key = "user_" .. findplr.userId
BanDataStore:SetAsync(key, 1)
end
end
end
--
But how do I unbann the Player while the Player is not Online?
Is it possible?
You can use Players.GetUserIdFromNameAsync to get the user id of a player who is not currently in your game with only their username. Here is an example of how you could use it in your code:
local userId = Players:GetUserIdFromNameAsync(player)
BanDataStore:RemoveAsync("user_" .. userId)
Well, you can call it with a dot, but it’d error unless you pass the player as the first argument. OOP rules apply with instance methods. That’s to say, the following are the same:
All suggestions in this thread work with UserIds. The use of a username simply allows us to get the UserId associated with the username via GetUserIdFromNameAsync. Generally a good sentiment to have though: if it doesn’t involve display, player work should normally always be conducted with their UserId.