HTTP 400 Error with character creation

Hello, I am trying to randomly generate users, and put them on the map, but the problem is that sometimes I recieve the error:
Players:CreateHumanoidModelFromUserId() failed because HTTP 400 (Bad Request) - Server - BotGeneration:17

	local botName
	local newId = math.random(100000000,7000000001)
	local success, err = pcall(function()
		botName = game.Players:GetNameFromUserIdAsync(newId)
	if not success then
	local bot = Players:CreateHumanoidModelFromUserId(newId)

How would I fix this, this only happens around 25% of the time, and it’s on this line:

	local bot = Players:CreateHumanoidModelFromUserId(newId)
1 Like

I don’t think this line of code would work too if that line didn’t work.

You can certainly use pcall to detect when a function errors, and then subsequently retry the random user ID. For more information, check out this post:


sorry had to test before posting … gl

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.