Unban Player Command Even If Offline

elseif SplitCommand[1] == ":unban" or SplitCommand[1] == ":Unban" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)

Here’s some of my code but if a palyer’s banned they can’t join back… so how would this unban them? But like how would I make it when I type the player’s username it will unban them EVEN if they’re offline or not in game (since if ur banned u can’t join back) I’m not asking for how to make it unban someone I’m asking for how can it detect a player even if they’re not in game since they’re banned

2 Likes

You already have the piece of code to find a player.

--Like these:
local Players = game:GetService("Players")
if Players:FindFirstChild(TargetPlayer) then
    -- player found in the server.
else
    -- player not found in the server.
end
1 Like

I not talking bout that. I mean since they’re banned it’s gona unban them but when typing their user they won’t be in a server. So how can I make it when the player is offline since they cant join the game back since they banned

local TargetedPlayer = SplitCommand[2]
-- // Assuming you store userids in the datastore,
local userid = game.Players:GetUserIdFromName(TargetedPlayer)
datastore:RemoveAsync(userid)
-- you mightve added a suffix or a prefix to the key, add that id u did
1 Like

Does the ban system have DataStore? if yes, just take the data from it and get find the banned player (UserId/Username) in there.

1 Like

Would this work?

				--Unban Player
			elseif SplitCommand[1] == ":unban" or SplitCommand[1] == ":Unban" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				BanDataStore:RemoveAsync(TargetedPlayer)
				--Unban Player
1 Like

Ok… would this code work?

				--Unban Player
			elseif SplitCommand[1] == ":unban" or SplitCommand[1] == ":Unban" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				BanDataStore:RemoveAsync(TargetedPlayer)
				--Unban Player
1 Like

Yes, but did it work ??

1 Like

Let me test it out. Be right back

2 Likes

I tried banning my alt account and it banned everyone in game… Say waht??

-Ban Player
			elseif SplitCommand[1] == ":ban" or SplitCommand[1] == ":Ban" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Name:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
				
				local Success, ErrorMessage  = pcall(function()
					BanDataStore:SetAsync(Player.UserId, true)
				end)
				if Success then
					Player:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
				else
					warn(ErrorMessage)
				end
				--Ban Player

--Check if player is banned
game.Players.PlayerAdded:Connect(function(Player)
	local Banned
	local Success, ErrorMessage  = pcall(function()
		Banned = BanDataStore:GetAsync(Player.UserId)
	end)
	if Banned == true then
		Player:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
	end
	if Success then

	else
		warn(ErrorMessage)
	end
end)
--Check if player is banned

THat’s my code

this for banning the player not unbanning. why did it just ban everyone in game…

Show me your current unban code

I didn’t even test it out… I tried banning the player to test it out but I dind’t even get a chance to

It doesn’t matter bout unban rn, why did my ban code just ban everyone in the game

Uhh Ima make another dev forum post bout this issue. Not sure what’s going on

				--Unban Player
			elseif SplitCommand[1] == ":unban" or SplitCommand[1] == ":Unban" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Ban:SetAsync(TargetedPlayer.UserID, false)
				--Unban Player

When the player was offline and I did :unban in the chat they were still banned. Any solutions?

```lua
				--Unban Player
			elseif SplitCommand[1] == ":unban" or SplitCommand[1] == ":Unban" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Ban:SetAsync(TargetedPlayer.UserID, false)
				--Unban Player

UserID is not a property

also u did it wrong

1 Like

Hmmm. What should I change? Adding characters

1 Like