How to make an npc look like a random player

I have an npc and i want it to look like a random player. just a random player. thats it. nothing specific. I have no idea how to do this except i thought of using createhumanmodelfromdescription or something like that. Please help im desperate

local function findnewDesc()
	local humanoid = script.Parent:WaitForChild('Humanoid')

	local UserId = math.random(900000,1900000000)


	local HumanoidDescription 

	local suc ,erro = pcall(function()

		HumanoidDescription =   game.Players:GetHumanoidDescriptionFromUserId(UserId)
	end)
	if suc then
		humanoid:ApplyDescription(HumanoidDescription)
	else 
		wait()
		print(erro)
		findnewDesc()
	end	
end
findnewDesc()

1 Like

If you want a random user on roblox, use @Concatenate_Nil’s script, if you want the NPC to look like a random user in your game then use a similar script, it would look like this:

local Players = game:GetService("Players")
local NPC = script.Parent
local function ApplyDisguise()
    local Humanoid = NPC.Humanoid
    local RandomUser = Players:GetPlayers()[#Players:GetPlayers()].UserId

    local HumanDesc
    local success, err = pcall(function()
        HumanDesc = Players:GetHumanoidDescriptionFromUserId(RandomUser)
    end)
    if success then
        Humanoid:ApplyDescription(HumanDesc)
    else
        warn(err)
        print("Trying again!")
        ApplyDisguise()
    end
end

Now when you’re ready to apply the disguise, simply call the function!

1 Like

Thank you @Concatenate_Nil and @domboss37 for the help! If you can, please try to explain this to me so I don’t just go hippity hoppity your stuff is now my property

This works, but the head looks weird. How do I fix it? I also want it to be the actual player’s head, not just the default head.

The head should be the random players head? I tested my code on a loop and it seemed to work for me.

The code uses math.random(900000,1900000000) to find a random UserID, i chose 900000 as the starting point as alot of users before that have the old OG default character and it looked strange. The “pcall(function()” just checks to see if there is a valid description for that UserId (will return an error if user is banned, and then will chose another random ID) . If there is a valid description then it will apply it to the Humanoid

This is what the npc looks like:

This is what the npc looks like in studio:
Screen Shot 2022-10-10 at 5.41.41 PM

RandomPlayerID.rbxl (45.3 KB)

I want to use r6, that’s why. I don’t know why its not working
Edit: Ohhh, I know why. It didn’t have a mesh for the head so it didn’t work

Updated to R6 dummy. I believe it was because there was no SpecialMesh inside of the head.
RandomPlayerID.rbxl (39.5 KB)

This text will be blurred

1 Like

I have another error, for some players, the accessories are not placed right. I want to remove all accessories other than hats, is this possible?


script.Parent.ChildAdded:Connect(function(child)
	if child:IsA("Accessory") then
		if child.AccessoryType ~= Enum.AccessoryType.Hat then
						
			child:Destroy()
		end
	end
end)

Would I put this in a new script? or the same one

The same one will be fine, put it above the findNewDesc function

How would this also be for hair too? I tried this but it didn’t work

script.Parent.ChildAdded:Connect(function(child)
	if child:IsA("Accessory") then
		if child.AccessoryType ~= Enum.AccessoryType.Hat then

			child:Destroy()
		end
	end
end)
script.Parent.ChildAdded:Connect(function(child)
	if child:IsA("Accessory") then
		if child.AccessoryType ~= Enum.AccessoryType.Hat and child.AccessoryType ~= Enum.AccessoryType.Hair then 
			child:Destroy() 
		end
	end
end)

It still doesn’t work… :confused:

This text will be blurred

Could you send me all of your code?

script.Parent.ChildAdded:Connect(function(child)
	if child:IsA("Accessory") then
		if child.AccessoryType ~= Enum.AccessoryType.Hat and child.AccessoryType ~= Enum.AccessoryType.Hair then 
			child:Destroy() 
		end
	end
end)

local function findnewDesc()
	local humanoid = script.Parent:WaitForChild('Humanoid')

	local UserId = math.random(1,1900000000)


	local HumanoidDescription 

	local suc ,erro = pcall(function()

		HumanoidDescription =   game.Players:GetHumanoidDescriptionFromUserId(UserId)
	end)
	if suc then
		humanoid:ApplyDescription(HumanoidDescription)
	else 
		wait()
		print(erro)
		findnewDesc()
	end	
end
findnewDesc()