20:01:44.824 - attempt to yield across metamethod/C-call boundary

hi, i was making a FFA and when the Caps button is pressed, the players from ur team will be chosen but sometimes i got these errors:

20:01:44.824 - attempt to yield across metamethod/C-call boundary

and:

20:01:44.975 - cannot resume non-suspended coroutine

the script:


function Change()
	script.Parent.MainFrame:ClearAllChildren()
	for _,Character in ipairs(game.Players:GetChildren()) do
		Character = Character.Character
		local t,t2 = Character:FindFirstChild('Team'),game.Players.LocalPlayer.Character:FindFirstChild('Team')
		if t and t2 then
			if t.Value == t2.Value then
				local clo = script.Map:Clone()
				table.foreachi(clo:GetChildren(),function(_,Child)
					Child.Parent = script.Parent.MainFrame
					Child.Visible = true
					if Child.Name == 'PNameL' then
						Child.Text = Character.Name
					elseif Child.Name == 'PlayerImage' then
						Child.Image = game.Players:GetUserThumbnailAsync(game.Players[Character.Name].UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size180x180)
					elseif Child.Name == 'Kills' then
						Child.Text = string.format('Kills: %s',Character:WaitForChild('Kills').Value)
					end
				end)
				spawn(function()
					clo:Destroy()
				end)
				clo.Parent = script.Parent.MainFrame
				for _,Children in ipairs(clo:GetChildren()) do
					if #script.Parent.MainFrame:GetChildren() >= 1 then
						for _,Children2 in ipairs(script.Parent.MainFrame:GetChildren()) do
							Children.Position = UDim2.new(Children2.Position.X.Scale,Children2.Position.X.Offset - 0.191,Children2.Position.Y.Scale,Children2.Position.Y.OffSet)
						end
					end
				end
			end
		end
	end
end

the error line:


Child.Image = game.Players:GetUserThumbnailAsync(game.Players[Character.Name].UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size180x180)

table.foreach and table.foreachi were deprecated in Lua 5.1. The function you’re passing to it calls methods that yield, like GetUserThumbnailAsync and WaitForChild, and it isn’t allowed to yield. You should use a loop to iterate over the table like you do with the players.

2 Likes

oh, and what Deprecated means?

Essentially, deprecated means that these functions have been replaced, or are in the process of being replaced, by newer functions. These methods are no longer advised, and should be updated to the newer methods. In this case, I don’t know what the newer methods are. More info is here: Deprecated Definition - What does deprecated mean?.

A succinct way to describe it is that deprecated means “Should not be used in new code”: It still exists, and works for the time being in existing code, but you shouldn’t use it in new code because it may eventually be removed entirely.