Infinite yield possible on 'Workspace.itz_rennox:WaitForChild("Head")'

[Sry for bad english]

I made a script that spawns a part on the Player head
It works fine but if the player dies then I get this warning:

Infinite yield possible on 'Workspace.itz_rennox:WaitForChild("Head")'

Stack Begin
15:12:05.167 - Script 'ServerScriptService.Bolt.Script', Line 9
15:12:05.168 - Stack End

Then the script dont work anymore

This is the Script :

game.ReplicatedStorage.Bolt.Bolt.OnServerEvent:Connect(function(plr)
	if plr.CD.Value == true then
	else
		wait(0.1)
	plr.CD.Value = true
	local char = plr.Character or plr.CharacterAdded:Wait()
	local CloneBolt = game.ReplicatedFirst.GameObj.Bolt:Clone()
	CloneBolt.Parent = game.Workspace.Storage.Bolt
	CloneBolt.CFrame = CFrame.new(char:WaitForChild("Head").Position)
	CloneBolt.CFrame = CloneBolt.CFrame * CFrame.fromEulerAnglesXYZ(0,-0.5,-1.5)
	CloneBolt.Sound:Play()
	wait(1)
	plr.CD.Value = false
	CloneBolt:Destroy()
	end
end)

Firstly, change character added to:

	local char = plr.Character or plr.CharacterAppearanceLoaded:Wait()

(This event fires when all of the characters parts have loaded in)
Secondly, I’ve heard adding the second argument of WFC can fix this,

	CloneBolt.CFrame = CFrame.new(char:WaitForChild("Head",5).Position)

Thirdly, you could just get the Head’s CFrame,

	CloneBolt.CFrame = char:WaitForChild("Head",5).CFrame

Dont work for me

But thank you for your help

Does it still have an infinite yield? Maybe try FindFirstChild.

Yep still have an infinite yield
FindFirstChild dont work

If WaitForChild is giving you an infinite yield then FindFirstChild would only give you nil.

I do not think that this warning is related to the code you have posted as “Workspace.itz_rennox” is not used in this code. Double check where this is from.

In most cases you can click on the output line to bring up the script where the output is from.

make a head variable right below char

local head = char:FindFirstChild(“Head”) or char:WaitForChild(“Head”, 10)

that should work but not 100% sure

Dont work :

ServerScriptService.Bolt.Bolt:10: attempt to index local ‘head’ (a nil value)

Do you have any other scripts that might be affecting the Head? The code you provided seems fairly working to me and shouldn’t be making the error you’re giving.

I found the mistake

When I died I always spammed the mouse button xD

My new script :

game.ReplicatedStorage.Bolt.Bolt.OnServerEvent:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	if char:WaitForChild("Humanoid").Health <= 0 then
		else

	if plr.CD.Value == true then
	else
		wait(0.1)
	plr.CD.Value = true
	local CloneBolt = game.ReplicatedFirst.GameObj.Bolt:Clone()
	CloneBolt.Parent = game.Workspace.Storage.Bolt
	CloneBolt.CFrame = CFrame.new(char:WaitForChild("Head").Position)
	CloneBolt.CFrame = CloneBolt.CFrame * CFrame.fromEulerAnglesXYZ(0,-0.5,-1.5)
	CloneBolt.Sound:Play()
	wait(1)
	plr.CD.Value = false
	CloneBolt:Destroy()
	end
	end
end)