Why is it giving me this error randomly?

wait()

local id = math.random(1,1000000000)

local hum = script.Parent.Humanoid

local newHumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(id)

local Name = game.Players:GetNameFromUserIdAsync(id)

hum:ApplyDescription(newHumanoidDescription)

script.Parent:FindFirstChildOfClass(“Humanoid”).DisplayName = Name

This script gets a random player id and applies it to a dummy it works as usual but sometimes their is a error the error being, “Players:GetHumanoidDescriptionFromUserId() failed because HTTP 400 (Bad Request)” How do i fix this?

My guess is there’s a chance the random ID might not be good. This is a situation where it is good to wrap the function in a pcall statement.

wait()

local hum = script.Parent.Humanoid
local id
local newHumanoidDescription
local name
local successful

repeat
	id = math.random(1,1000000000)
	successful = pcall(function()
		newHumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(id)
		name = game.Players:GetNameFromUserIdAsync(id)
	end)
until (successful)

hum:ApplyDescription(newHumanoidDescription)
script.Parent:FindFirstChildOfClass(“Humanoid”).DisplayName = name

This code will keep trying random IDs until it can successfully retrieve a humanoid description and username.

Sorry for the late reply had homework, ill test this out

Works good thanks alot again sorry for late reply.

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