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