Infinite Yields, Help

Hi, I am trying to change an accessory with it’s Handle1 but it doesn’t work because of an infinite yield. This is the error:

  16:27:03.732  Infinite yield possible on 'Chickennuggetmanwow.DOGE:WaitForChild("Handle1")'  -  Studio

And this is my code:

local Players = game:GetService("Players")
local Player = game:GetService("Players").LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Statue = workspace.Statue.Char

local Players = game:GetService("Players")
local Player = game:GetService("Players").LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Statue = workspace.Statue.Char -- Assuming "Statue" is a Model in the workspace

function ScaleModel(model, scale)
	for i, part in ipairs(Statue:GetDescendants()) do
		if part:IsA("BasePart") then
			part.Size = part.Size * scale
		end
	end
end

-- Player Item Functions
function Pants(v) -- Pants Function
	v.PantsTemplate = "rbxassetid://0"
end

function Shirt(v) -- Shirt Function
	v.ShirtTemplate = "rbxassetid://0"
end

function Accessory(v, Material, Color) -- Accessory Function
	local Handle1 = v:WaitForChild("Handle1")
	
	Handle1.TextureID = "rbxassetid://0"
	Handle1.Material = Material
	Handle1.Color = Color
end

function Part(v, Material, Color) -- Part Function
	v.Material = Material
	v.Color = Color
end

function BaseAppearance(Morph, MorphHumanoid, Scale, Material, Color)
	
	MorphHumanoid:WaitForChild("BodyHeightScale").Value *= Scale
	MorphHumanoid:WaitForChild("BodyDepthScale").Value *= Scale
	MorphHumanoid:WaitForChild("BodyWidthScale").Value *= Scale
	MorphHumanoid:WaitForChild("HeadScale").Value *= Scale
	
	for i, v in pairs(Morph:GetChildren()) do
		if v:IsA("Pants") then
			Pants(v)
		elseif v:IsA("Shirt") then
			Shirt(v)
		elseif v:IsA("Accessory") then
			Accessory(v, Material, Color)
		elseif v:IsA("Part") then
			Part(v, Material, Color)
		end
	end
	
end
function StatueAppearance()
	Character.Archivable = true
	local CharacterMorph = Character:Clone()
	local MorphHumanoid = CharacterMorph:WaitForChild("Humanoid")
	
	local Scale = 15
	local Material = Enum.Material.Neon
	local Color = Color3.new(1, 0.0112306, 0)
	
	BaseAppearance(CharacterMorph, MorphHumanoid, Scale, Material, Color)
	

	
	CharacterMorph:SetPrimaryPartCFrame(Statue.PrimaryPart.CFrame) -- Set the character's position to match the Statue's position

	-- Calculate the scaling factor based on the desired size of the Statue
	local scaleFactor = Statue.PrimaryPart.Size.X / Character.PrimaryPart.Size.X -- Assuming the size is proportional in the X direction

	-- Apply the scaling to all parts of the cloned character
	--ScaleModel(CharacterMorph, scaleFactor)

	Statue:ClearAllChildren()
	CharacterMorph.Parent = Statue
	Character.Archivable = false
end

StatueAppearance()

The issue goes from line 34 to line 40. I think it’s at line 35 as that’s where the waitforchild is. Please help.

2 Likes

There most likely isnt a child named “Handle1”

1 Like

There is, look:

1 Like

Oh, it must be running the function before the meshpart is created in the workspace

2 Likes

I’m not very good at Infinite Yields, but try using a Wait() before calling Handle1 because as @CodyTheDwagon said, it must be running the function before the meshpart is created in the workspace.

1 Like

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