Help with HumanoidModelFromDescription / Unable to Cast Token

I’m having trouble creating a Humanoid Model from a Humanoid Description. (from a random username/id from the users list)

I believe I’ve used this exact same script structure before with no issues but for some reason I keep receiving this error:

10:24:06.750  Error! | No Character Spawn Success: |   -  Server - Npc_CustomerX:89
10:24:06.750  Unable to cast token to token  -  Server - Npc_CustomerX:90

Here is my Script:

local PathfindingServ = game:GetService("PathfindingService")
local PlayersServ = game:GetService("Players")
local HttpServ = game:WaitForChild("HttpService")

local SpawnPosition = Vector3.new(47.019, 72.074, -18.353)

local ListOfUsersToGenerate = {
	"C_Sharper",
	"Scrixt",
	"BlackBeardTheGoat",
	"ubermemoli",	
	"Wizzthepixelcat", 
	"zektonn",
	"Chanxl",
	"MisterRedTurtle",
	"Amphiriteal",
	"GlobeBloxxer",
	"Kairomatic",
	"SenSempre",
	"xMaverickGunnerx",
	"Parasoleil",
	"MisterGreenTurtle",
	"Lvl100SuperBurrito",
	"LuaCow",
	"koaffle",
	"Kepzun",
	"InceptionTime",
	"CountLoops",
}

local function SpawnNpcCustomer()
	
	local RandomIndex = math.random(1, #ListOfUsersToGenerate)
	local Username = ListOfUsersToGenerate[RandomIndex]
	local UserId = PlayersServ:GetUserIdFromNameAsync(tostring(Username))
	
	
	local InfoTable = {
		Index = RandomIndex,
		Username = Username,
		UserId = UserId
	}
		
	print("*-- Player Spawn Info: --*")
	print(InfoTable)
	
	
	local DescSuccess, HumiDesc = pcall(function()
		local DescNeeded = game.Players:GetHumanoidDescriptionFromUserId(tonumber(UserId))
		return DescNeeded
	end)
	
	
	wait(2)
	
	if DescSuccess then
		
		local SpawnSuccess, Char = pcall(function()
			wait(2)
			local HumanoidModel = PlayersServ:CreateHumanoidModelFromDescription(HumiDesc, Enum.RigType.R15, Enum.AssetTypeVerification.Always)
			return HumanoidModel
		end)
		
		
		
		if SpawnSuccess then
			
			local PrimaryCharPart = Char.PrimaryPart
			local Humanoid:Humanoid = Char:FindFirstChildWhichIsA("Humanoid", true)
			
			PrimaryCharPart.Position = SpawnPosition
			
			local Destination = Vector3.new(-6.76, 70.087, -70.787)
			
			local Path = PathfindingServ:FindPathAsync(SpawnPosition, Destination)
			print("Path Created")
			
			for i, Point in pairs(Path:GetWaypoints()) do
				Humanoid:MoveTo(Point)
				Humanoid.MoveToFinished:Wait()
				wait(0.5)
				print("Point Reached")
			end
			
			
		else -- No Character Spawn Success:
			warn("Error! | No Character Spawn Success: | ")
			warn(Char)
		end
	else -- No Humanoid Desc Success:
		warn("Error! | No Humanoid Desc Success: |")
		warn(HumiDesc)
	end
	
	
end -- End SpawnNpcCustomer Function



script.Parent.OnServerEvent:Connect(function()
	SpawnNpcCustomer()
end)

Has anyone else had a similar issue with this or am I just making a silly mistake haha? Any help I would appreciate! :slight_smile:

:man_facepalming:t4: Thank you! That was my problem… and I use CreateHumanoidModelFromDescription() because for some reason some player avatars fail to load / be at correct positions for me when they’re not updated to R15.

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