How to check if a player is banned in a repeat until loop?

I’m trying to check whether or not a certain player is banned, but it just wont work.

	local Success, Error = pcall(function()
		repeat
			ID = math.random(1,50)
			print(game.Players:GetPlayerByUserId(ID))
			local Info = MarketPlaceService:GetProductInfo(ID)
		until game.Players:GetPlayerByUserId(ID) ~= nil
	end)

GetPlayerByUserId will return true only if a player is currently in that specific game server. Not if they aren’t banned.

2 Likes

You will have to use a third-party API that retrieves banned player info. ROBLOX has an API for player data, but for some reason it is currently down.

^ The API will return an isBanned boolean.

How long has it been down for?

I’m not sure. I accessed the API two weeks ago and I haven’t checked since.

https://users.roblox.com/docs/index.html#!/Users/post_v1_usernames_users
^ You will be directed to a 404 page.

2 Likes

If you don’t want to use web APIs you can try this hacky method.

You can pcall game.Players.GetCharacterAppearanceInfoAsync, as it throws HTTP 400 (Bad Request) if you use it on a banned player. You can probably find other methods that do the same.

local function is_banned_by_roblox(id)
	return not pcall(Players.GetCharacterAppearanceInfoAsync, Players, id)
end

This is hacky for a few reasons:

  1. Future changes to the implementation of this method might break your game logic; this is not the intended functionality so you can’t really expect them to keep it this way.
  2. You can’t guarantee that all bad requests are the result of the player being banned.

For a production game I would recommend using Roblox’s API and only resorting to this when it is unavailable (like right now). I’ve also never used this in a real game so I have no idea if any issues might be amplified by things like request count.

2 Likes