Infinite yield error when item already exists

Hi, I am making a module that tweens and reset welds and I have run into this error:

But when I look into the player, “RIght Shoulder” already exists even before the error.

image

Module script:

local player =  Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local Torso = character:WaitForChild("Torso")
local Head = character:WaitForChild("Head")
local RA = character:WaitForChild("Right Arm")
local LA = character:WaitForChild("Left Arm")
local RL = character:WaitForChild("Right Leg")
local LL = character:WaitForChild("Left Leg")

function Tween.TweenWeld(TargetLimb, StartCFrame, CFrame0, EasingDirection, EasingStyle, Duration)
	EditLimb:FireServer(TargetLimb, CFrame0)	
	
	local weldExists = false
	local weld = nil
	local appendiges = {RA, LA, RL, LL, Head}
	local correspondingJoints = {Torso:WaitForChild("Right Shoulder"), Torso:WaitForChild("Left Shoulder"), Torso:WaitForChild("Right Hip"), Torso:WaitForChild("Left Hip"), Torso:WaitForChild("Neck")}
	
	local EndCFrame = {}
	EndCFrame.C0 = CFrame0 

	local Info = TweenInfo.new(Duration,EasingStyle,EasingDirection)
	
	for _, v in pairs(Torso:GetChildren()) do
		if v.Name == "Weld" and v.Part1.Name == TargetLimb then
			weldExists = true
			weld = v
		end
	end

	if not weldExists then
		weld = Instance.new("Weld")
	end 
	
	for i,v in pairs(appendiges) do
		if TargetLimb == v.Name then
			correspondingJoints[i].Part1 = nil
			
			weld.Parent = Torso
			weld.Part0 = Torso
			weld.Part1 = v
			weld.C0 = StartCFrame
			local Animation = TweenService:Create(weld, Info, EndCFrame)
			Animation:Play()
		end
	end
end

Any help would be appriciated, thanks!

Before setting the variable, can you print Torso:WaitForChild("Right Shoulder")?

1 Like

image

Hm… Try adding a 0.2 parameter after “Right Shoulder” in the WaitForChild

By the way, I am makig mobile tools, the pc tools use the same scripts and work, all I did is add a MouseButton1Click. I can give you the mobile script if you want

By the way, I added the .2 parameter and now it gives me this error