"Players:BanAsync()" new feature

Hey, so I saw that roblox released a new ban API, people can use :BanAsync() and :UnbanAsync() :to ban players from their game.
(Release Notes for 622 | Documentation - Roblox Creator Hub)

Im just wondering, is there a way to check who is banned from the experience?

8 Likes

I believe so, you can check scripts because your the one banning the person. This feature allows you to ban in studio or whatever.
If your script somehow looks like this then you can


local playerToBan = game.Players:GetPlayerByName("PlayerName")

if playerToBan then

    local success, errorMessage = pcall(function()
        playerToBan:BanAsync("Inappropriate behavior", 7)
    end)

    if success then
        print("Player has been banned successfully.")
    else
        warn("Error banning player: " .. errorMessage)
    end
else
   warn("Player not found.")
end

See how there is a PlayerName?
That’s how you check/remember.

2 Likes

Even though Release Notes for 622 says:

Releases beta version of banning APIs: BanAsync and UnbanAsync

It’s not available for developers to use yet, as it still shows Pending. It won’t take effect until it’s updated to the status of Live.


I’d imagine there will be a way to check, or else there could end up being situations where malicious free models use that API to ban everyone that joins a game without any way for the owner(s) of a game to know with 100% certainty how many players were banned and who specifically was banned.

Once the feature becomes available for developers to use, it’s very likely that there will be an announcement on the Developer Forum about it which details how it works, including an explanation for how a developer can check who has been banned from their game.

2 Likes

This is incorrect, You’d do it like this.

local players = game:GetService('Players')

players.BanAsync({UserIds = {1,2}, Duration = 7, DisplayReason = "String" }) -- There are more options. (Duration is in seconds)

Check this for more

1 Like

I don’t see a way to get a list of who is banned, but seems like this is the way to check a given player to see if they are banned:
https://create.roblox.com/docs/reference/engine/classes/Players#GetBanHistoryAsync

you can check ban start time and duration with that

1 Like

There isnt an actual way but what u can do i use players:GetBanHistoryAsync() and just loop thru the table it gives to see if there is a ban that is active (By checking if the BanHistoryPages.Ban1.Ban equals true)

1 Like

So, when they first announced this update a few months ago, i started working on a plugin. I set up everything so when they released the update, all I had to do was add the ban/unban command.

Sadly, after testing, i get an error:
BanAsync() can only be called on the server

It is a server script
image

Here is my script:

local config: BanConfigType = {
		UserIds = {2758548757},
		Duration = 500,
		DisplayReason = 'test',
		PrivateReason = 'test2',
		ExcludeAltAccounts = false,
		ApplyToUniverse = true
	}

	local success, err = pcall(function()
		return Players:BanAsync(config)
	end)

if success then
    print(success)
else
  warn(err)
end

This might be because it needs to be a descendant of a server locked service (Such as ServerStorage and ServerScriptService)

Add me on discord (@classicsenior#0) and i’ll be able to reply quicker.

There no such thing as GetPlayerByName besides GetPlayerByUserId

GetPlayerByUserId is a lot more reliable anyway

Using the request
https://apis.roblox.com/cloud/v2/universes/{PlaceUniververseID}/user-restrictions:listLogs

That way you can fetch all the bans/unbans on that universe which looks like this: