Issue with loading character (humanoid model)

I have looked all over for a solution for this, but haven’t found anything since this is a very obscure problem. Basically, I have 2 leaderboards in my game, which both work fine. I recently added something that displays the top player’s avatar, for each leaderboard. I am using

game.Players:CreateHumanoidModelFromUserIdAsync()

This works fine for my first leaderboard, but for the second one (which has a different player as the #1 player) the script says “infinite yield possible on Character:WaitForChild(‘Head’)” which makes no sense, because when I tried loading in the character outside of the game in the command line, the character definitely has a head. I am very confused by this, and what’s even more confusing is that sometimes the code actually works, (around 30% of the time), but most of the time it just says infinite yield. Please help! Also this has a tendency to work more in studio than in the real game, works ~30% of the time in studio and ~5% of the time in game.
.

3 Likes

I may just have had the same issue as you
Try defining the head with a timeout
local plr = game.players.localplayer
local char = plr.character or plr.characteradded:wait()
local head = char:waitforchild(“head”, 5)

in the top of the script (and then redefine your variables and humanoid if needed)

1 Like

? There is no player or player.Character. I am creating a character (humanoid model) with

game.Players:CreateHumanoidModelFromUserIdAsync()

from a server script. The issue is that sometimes the head cannot be found in this new character.

1 Like

hm. The issue you describe is exactly the issue I had with same % chance, except it was with a localscript leaderboard with a humanoidrootpart
if you can in any way define the head variable early in your serverscript with a “timeout” maybe it could solve it. Maybe even putting it in the actual waitforchild statemnt you currently have would solve it. Otherwise Idk sorry.

Character:WaitForChild(“Head”, 5)

1 Like

I can’t define it at the top of the server script because I need the character to be created at that specific spot in the script. I have also tried using :WaitForChild(‘Head’, 5) and I have tried using a

repeat wait() until

loop.

2 Likes

yea Idk what it is. Hopefully someone else knows. Roblox ping messes with a lot of character scripts.

1 Like

?? Bro its a server script, its nothing to do with roblox ping.

figured it was caused by ping as the variables load at different times when testing in studio compared to testing in-game and is not determenistic (which implies variables changing in the background). Anyway I don’t want to spiral and get off topic. I hope you find a solution for this issue

I don’t see how it could be ping-related considering it is a server-script, but yeah thanks for trying to help and I hope someone else knows the answer!

Bumping this because I still need help, hoping someone has the solution.

Can you show the part of the script which is erroring?

Yeah sure, give me a second to find and copy it.

I am using repeat task.wait() until humanoidModel:FindFirstChild(‘Head’) instead of :WaitForChild, and it keeps printing “Waiting for head to load” indefinitely.

local humanoidModel = plrs:CreateHumanoidModelFromUserId(tonumber(page[1].key))

			print('Created', humanoidModel)
			
			if humanoidModel then
				humanoidModel.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
				humanoidModel.Name = 'Character'

				humanoidModel.HumanoidRootPart.Anchored = true

				humanoidModel.Parent = ws:FindFirstChild('Worlds'):FindFirstChild('1'):FindFirstChild('TopPlayerDisplays')
				print('Angles', CFrame.Angles(0, ws:FindFirstChild('Worlds'):FindFirstChild('1'):FindFirstChild('TopPlayerDisplays'):FindFirstChild('Rebirths').Rotation.Y, 0))
				humanoidModel:PivotTo(CFrame.new(ws:FindFirstChild('Worlds'):FindFirstChild('1'):FindFirstChild('TopPlayerDisplays'):FindFirstChild('Rebirths').Position + Vector3.new(0, humanoidModel:GetBoundingBox().Y + 0.5, 0)))

				local animation = Instance.new('Animation')
				animation.AnimationId = 'rbxassetid://15392759696'

				local animationTrack = humanoidModel.Humanoid.Animator:LoadAnimation(animation)
				animationTrack:Play()

				print('Parented')

				local number1PlayerInfo = script:FindFirstChild('Number1PlayerInfo'):Clone()

				local success, result = pcall(function()
					return us:GetUserInfosByUserIdsAsync({tonumber(page[1].key)})
				end)

				print('Result is', result)

				if success then
					number1PlayerInfo.PlayerName.Text = result[1]['DisplayName']
				else
					number1PlayerInfo.PlayerName.Text = ''
				end

				print('Set')

				repeat task.wait(0.1) print('Waiting for head to load') until humanoidModel:FindFirstChild('Head')

				number1PlayerInfo.Parent = humanoidModel:FindFirstChild('Head')
				number1PlayerInfo.Adornee = humanoidModel:FindFirstChild('Head')
				number1PlayerInfo.Enabled = true

				print('Adorneed/parented')
			else
				print('No humanoid Model')
			end

I went on studio to see if this was a bug with CreateHumanoidModelFromUserId() and it isn’t.

game:GetService("Players").PlayerAdded:Connect(function(plr)
	local CloneHumanoid = game:GetService("Players"):CreateHumanoidModelFromUserId(plr.UserId)

	CloneHumanoid.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None

	repeat task.wait(0.1) print("Waiting for head to load") until CloneHumanoid.Head

	if CloneHumanoid.Head then
		print("Head exists")
	end
end)

Have you tried debugging in your actual script to make sure it’s being created?

Head does not exist, which is the problem. I have no idea why, because when I call CreateHumanoidModelFromUserId() from the command prompt in studio, with the EXACT SAME userid the character has a head. (like I said, I used the repeat statement to wait until the head exists, but it never got created. (it gets created for other peoples avatars in game and in studio, but for this player it will only work in studio.)

What’s this line local humanoidModel = plrs:CreateHumanoidModelFromUserId(tonumber(page[1].key)) inside of? Are you sure this script isn’t only running once so the other character won’t be created?

The other character is created. I have looked at the debugging and it just gets stuck on the repeat task.wait() part.

Instead of doing the repeat loop for the Head, do it for the entire Character and see if it’ll run.

wdym for the entire character?

Still can’t figure this out man I hope someone knows the answer