Infinite yield possible on 'waitforchild'

so i’ve been trying to optimize this grip to motor6d script and i thought i fixed it, but it didnt print the messages that i put at certain parts of the script to see if it was working.

There also showed a message in the output saying Infinite yield possible on ‘Players.AndyVT.Backpack:WaitForChild(“Right Arm”)’, so i looked it up but i couldnt find anything helpful

i tried switching around the findfirstchilds and waitforchilds to no avail.

-- Original script made by xSIXx.
-- Optimized and edited by AndyVT.

-- Place this script into the tool
-- to animate, add a motor6d to a dummy's torso, place the tool in the dummy group and connect the handle to the m6d's part1 and the torso as the part0.
-- after that it should be good to go! thank you for using my script.

-- variables

	local tool = script.Parent
	local character = script.Parent.Parent
	local rightHand	= character:WaitForChild("Right Arm")
	local torso = character:WaitForChild("Torso")

-- please don't touch this unless you know what you're doing, otherwise it can break the script. I'll type out a rough explanation below.

tool.Equipped:connect(function()

	local getWeld = rightHand:FindFirstChild("RightGrip")	-- variable to find the default weld that is added whenever a tool is equipped	
	local motor = Instance.new("Motor6D") -- variable that creates the motor6d
	motor.Name = "GripM6D" -- sets the name of it to "gripm6d" edit if you want
	motor.Part0 = torso -- sets the part0 of the motor6d to the torso (the variable is on line 10)
	motor.Part1 = getWeld.Part1	-- sets the part1 of the motor6d to the default weld's part1, which in this case is the handle of the tool.
	motor.Parent = torso -- puts the motor6d in the torso.
	getWeld:Destroy() -- destroys the default weld
	--motor.C0 = getWeld.C0 -- ngl i dont even know what this is
	--motor.C1 = getWeld.C1 
	print("get pwned weld")	-- identication that the script is working and that the default weld has been deleted.
end)

the problem is around the right hand, torso, and the get weld variables with the waitforchilds and findfirst childs.

any help would be appreciated, thanks!

1 Like

Try character:WaitForChild("RightArm")

I pretty sure the whitespace shouldn’t be there.

1 Like

This too, but this isn’t the problem. The script is running before it’s equipped to script.Parent.Parent is the player’s Backpack. Hence the error Players.AndyVT.Backpack:WaitForChild(“Right Arm”)

Easy fix, move your variables into the tool.Equipped function.

-- Original script made by xSIXx.
-- Optimized and edited by AndyVT.

-- Place this script into the tool
-- to animate, add a motor6d to a dummy's torso, place the tool in the dummy group and connect the handle to the m6d's part1 and the torso as the part0.
-- after that it should be good to go! thank you for using my script.

-- variables

	local tool = script.Parent
	

-- please don't touch this unless you know what you're doing, otherwise it can break the script. I'll type out a rough explanation below.

tool.Equipped:connect(function()

    local character = script.Parent.Parent
	local rightHand	= character:WaitForChild("Right Arm")
	local torso = character:WaitForChild("Torso")

	local getWeld = rightHand:FindFirstChild("RightGrip")	-- variable to find the default weld that is added whenever a tool is equipped	
	local motor = Instance.new("Motor6D") -- variable that creates the motor6d
	motor.Name = "GripM6D" -- sets the name of it to "gripm6d" edit if you want
	motor.Part0 = torso -- sets the part0 of the motor6d to the torso (the variable is on line 10)
	motor.Part1 = getWeld.Part1	-- sets the part1 of the motor6d to the default weld's part1, which in this case is the handle of the tool.
	motor.Parent = torso -- puts the motor6d in the torso.
	getWeld:Destroy() -- destroys the default weld
	--motor.C0 = getWeld.C0 -- ngl i dont even know what this is
	--motor.C1 = getWeld.C1 
	print("get pwned weld")	-- identication that the script is working and that the default weld has been deleted.
end)
2 Likes

Right Arm and Torso are members of an R6 character. Are you sure your character is R6?

1 Like

it fixed the first part, but now im greeted with “attempt to index nil with part1”

yea, i can assure you my character is in r6
image

Sorry for the late response, had to run to a working party for a little bit.
The error is coming from your

motor.Part1 = getWeld.Part1

The error means that getWeld is nil, so it can’t find a Part1 in it. So the script can’t find the first child, RightGrip of the Right Arm

its all good, im pretty sure i fixed it now, but for some reason now when i tested it with my friends, the gun looks like its in their torso, but on their screen its working just fine and its the opposite, a bit hard to explain so i’ll send an image below, got any suggestions?

image

Is the script a local script? If yes try changing it to a server script.

1 Like

no, i wrote it all in a server script, i tried both local and server without a difference