Infinite Yield Possible

I get error about Infinite Yield and I am new scripter I don’t know what to do

** Infinite yield possible on 'Tower1:WaitForChild(“HumanoidRootPart”)**

Here Script

local ReplicatedStroage = game:GetService("ReplicatedStorage")
local PlaceTower = game.ReplicatedStorage:WaitForChild("PlaceTower")
local Tower = game.ReplicatedStorage:WaitForChild("PreTower")
local PlaceLable = game.Workspace.PlaceLable

local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local Player = game.Players.LocalPlayer
local TowerMenu = script.Parent.TowerMenu
local char = Player.Character or Player.Character:Wait()
local HumanoidRootPartA = char:WaitForChild("HumanoidRootPart") 

local Mouse = Player:GetMouse()

local Ybuildingoffset = 1.5
local MaxPlacingDistance = 50
local rKeyIsPressed = false
local PlacingTower = false


for _, TowerButton in pairs(TowerMenu:GetChildren()) do
	if TowerButton:IsA("ImageButton") then
		TowerButton.MouseButton1Up:Connect(function()
			
			TowerMenu.Visible = false
			
			local yOrientation = 0
			local GoodToPlace = false
			local PlacedTower 
			
			if PlacingTower == false then
				PlacingTower = true
				local ClientTower = Tower:FindFirstChild(TowerButton.Name):Clone()
				ClientTower.RangeArea.BrickColor = BrickColor.new("Cyan")
				ClientTower.RangeArea.Material = "Neon"
				ClientTower.RangeArea.CanCollide = false
				ClientTower.Parent = game.Workspace
				local HumanoidRootPartH = ClientTower:WaitForChild("HumanoidRootPart")
				local RangeAreaB = ClientTower:FindFirstChild("RangeArea")
				local StartingCFrame = CFrame.new(0, -2, -15)
				ClientTower.HumanoidRootPart.CFrame = HumanoidRootPartH.CFrame:ToWorldSpace(StartingCFrame)
				
				for i, v in pairs(PlaceLable:GetChildren()) do
				print(v)
				RunService.RenderStepped:Connect(function()
					local MouseRay = Mouse.UnitRay
					local CastRay = Ray.new(MouseRay.Origin, MouseRay.Direction * 1000)
					local IgnoreList = {ClientTower, char}
					local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(CastRay, IgnoreList)
					local RangeAreaB = ClientTower:FindFirstChild("RangeArea")
						if hit and (hit:IsA(v) or hit.Name:lower() == v) and (HumanoidRootPartA.Position - HumanoidRootPartH.Position).Magnitude < MaxPlacingDistance then
						GoodToPlace = true
					end
					local NewanglesCFrame = CFrame.Angles(0, math.rad(yOrientation), 0)
					local NewCFrame = CFrame.new(position.X, position.Y + Ybuildingoffset, position.Z)
					ClientTower:WaitForChild("HumanoidRootPart").CFrame = NewCFrame * NewanglesCFrame -- heres the main problem
				end)
				end
				UIS.InputBegan:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.R then
						rKeyIsPressed = true
						
						local rotationspeed = 5
						while rKeyIsPressed do
							wait()
							if PlacingTower == true then
								yOrientation = yOrientation + rotationspeed
							end
						end
					end
				end)
				UIS.InputEnded:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.R then
						rKeyIsPressed = false
					end
				end)
				
				UIS.InputBegan:Connect(function(input)
					if input.UserInputType == Enum.UserInputType.MouseButton1 then
						if PlacingTower == true then
							if GoodToPlace == true then
								local TowerCFrame = ClientTower.HumanoidRootPart.CFrame
								print(TowerCFrame)
								PlacedTower = PlaceTower:InvokeServer(ClientTower.Name, TowerCFrame)
								if PlacedTower == true then
									PlacingTower = false
									ClientTower:Destroy()
									TowerMenu.Visible = true
								end
							end
						end
					end
				end)
				
			end
		end)
	end
end

Fun Fact: This script is so bad and unstable if you seeing something like bad thing you can tell me. thanks

Any other errors appearing in the console?

ClientTower.HumanoidRootPart.CFrame = NewCFrame * NewanglesCFrame -- heres the main problem

What happens when you try this?

As expected, that’s definitely weird since the first reference to “ClientTower.HumanoidRootPart” is valid.

ClientTower.HumanoidRootPart.CFrame = HumanoidRootPartH.CFrame:ToWorldSpace(StartingCFrame)

I’ll need to spend some time looking at the script.

Hello,

so first of all the “error” you are getting is not an error really. It is more of a warning to tell you something.

What infinite yield means that there is something being waited for but there is a chance that it may never be found. I don’t think this should really affect your code unless of course the child is never found then the rest of your code will not run.

(an example as shown by the error you are awaiting the humaniodrootpart which the warning system does not know you may get it)

well it did if I play this my entire computer go 100% CPU and make this game really lag

The issue is the child never appears as you can see in the second screenshot “HumanoidRootPart” is not a valid member of Model “Tower1"”.

1 Like
RunService.RenderStepped:Connect(function()
print(ClientTower)

Add this print function here please and test. If the print function prints nil then “ClientTower” is not reachable inside the function.

Yea I know I just thought I would say what I did because they said they where new to scripting so may not know what the warning message means.

Fair enough, for a new scripter the script is fairly advanced however, unless it was from a free model.

ammm it not kinda free model im just Research Devforum and do tactical Random :confused:

Untitled

Ok i fix it now

HumanoidRootPartH.CFrame = NewCFrame * NewanglesCFrame

and it work fine now