Script stopping after getting bad request (HTTP 400)

I’m trying to make a tycoon sort of game that loads npcs and puts the avatars of the players friends onto the npcs but ive ran into an issue where if the server has a bad request at getting the description ( Players:GetHumanoidDescriptionFromUserId() failed because HTTP 400 (Bad Request)) it completely stops the script from working and no further npcs are spawned.
Heres my code, thanks for any help.

while true do
	for i, droppers in ipairs(droppertable) do
		local randomFriend = usernames[math.random(#usernames)]
		local randomFriendNPC = npc:Clone()
		randomFriendNPC.PrimaryPart.Position = droppers.SpawnPoint.Position
		randomFriendNPC.Parent = script.Parent.DropperFriends
		local newHumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(randomFriend)
		randomFriendNPC.Humanoid:ApplyDescription(newHumanoidDescription)
	end
	wait(5)
end
1 Like

It’s the userid not the name 30CHAR

Oh sorry its some code i found i just havnt changed the name of the table yet, its storing the id’s

maybe it’s some website issues sometimes happens to me

Ive been letting the thing run for a couple tries and whenever the playerid is banned it errors, so i need a way to check if they are terminated

https://developer.roblox.com/en-us/api-reference/lua-docs/Lua-Globals

Wrap in pcall to handle any errors.

while wait(5) do
	for _, droppers in pairs(droppertable) do
		local randomFriend = usernames[math.random(#usernames)]
		local randomFriendNPC = npc:Clone()
		randomFriendNPC.PrimaryPart.Position = droppers.SpawnPoint.Position
		randomFriendNPC.Parent = script.Parent.DropperFriends
		local newHumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(randomFriend)
		randomFriendNPC.Humanoid:ApplyDescription(newHumanoidDescription)
	end
end

you made

 in ipairs

instead of

ìn pairs

EDIT: sorry, just found out ipairs does the same thing .-.