Infinite yield problem

Hello, I am trying to get it, but its not really working for me.
I am getting infinite yield everytime I die. Well, when I am spawning in at first everything is working fine, but when I reset it just says on the output, “infinite yield possible”

local saber = chr:WaitForChild("Lightsaber")

Thats the line where I have the problem. The character loads fine, but this is making it worse.
The saber spawns in before that line. I even checked the workspace if the player has the lightsaber on him, I even added wait before the line and still, infinite yield.

Could you post a bigger chunk of the script? It’s quite hard to fix something with just one line.

Local script:


local head = chr:WaitForChild("Head")
local torso = chr:WaitForChild("Torso")
local rarm = chr:WaitForChild("Right Arm")
local larm = chr:WaitForChild("Left Arm")
local rleg = chr:WaitForChild("Right Leg")
local lleg = chr:WaitForChild("Left Leg")
local human = chr:WaitForChild("Humanoid")
local hrp = chr:WaitForChild("HumanoidRootPart")

local animate = chr:WaitForChild("Animate")
local saber = chr:WaitForChild("Lightsaber")

Server script:

function weld(chr, saber, holster)
	local weld = saber.Handle.Handle
	weld.Parent = chr:WaitForChild("Right Arm")
	weld.Part0 = chr:WaitForChild("Right Arm")
	weld.Part1 = saber.Handle
	local holsterweld = holster.Handle.Handle
	holsterweld.Parent = chr:WaitForChild("HumanoidRootPart")
	holsterweld.Part0 = chr:WaitForChild("HumanoidRootPart")

	local chr = plr.Character
	local saber = game:WaitForChild("ServerStorage").Lightsaber:Clone()
	local holster = game:WaitForChild("ServerStorage").Holster:Clone()
	holster.Parent = chr
	saber.Parent = chr
	weld(chr, saber, holster) -- WELDING

I have added tiny waits for the script, guess that solved everything for me. Thanks for trying though.

The command :WaitForChild() has a secondary optional argument, which is how long (in seconds) it will wait before considering it an infinite loop.

You can do :WaitForChild("Lightsaber", 300) and the script will only consider it an infinite loop after 30 seconds of the Lightsaber not being found.

Keep in mind I’m not sure of the performance loses by adding in an exponential number.

I know this is already solved but just to interject - my father gave me some good advice I think you need

“Never synchronize by wait”

Changed my life 10/10
Don’t use wait to trigger events in your scripts unless nothing else relies on it basically