How to unban a player while not online?

[my english is bad lol]

Hello everyone :slight_smile:

I have this in my Admin Commands script :

--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?

1 Like

You could try banning by using their UserId.

1 Like

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)
2 Likes

Thank you :smile:

You are my Hero :smiley:

This uses : syntax, not . syntax!
It would be called as Players:GetUserIdFromNameAsync.

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:

Player:GetUserIdFromNameAsync(username)
Player.GetUserIdFromNameAsync(Player, username)
1 Like

I recommend banning them using their UserId because in your system, they could just change their name and get unbanned.

1 Like

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.

1 Like