Infinite yield possible on HumanoidRootPart

Hello devforum.

I made a door script using a tutorial on the devforum and when I test it, I get this error :
Infinite yield possible on ‘Workspace.Raven_fortnite3:WaitForChild(“HunanoidRootPart”)’

I tried searching on devforum for someone that had the same issue and it didn’t work.

-- SERVICES --

local uis, cas = game:GetService("UserInputService"), game:GetService("ContextActionService")
local cs, ts = game:GetService("CollectionService"), game:GetService("TweenService")

-- PLAYER & GUI VARIABLES --

local character = script.Parent
local players = game:GetService("Players")
local client = players.LocalPlayer

local root = character:WaitForChild("HunanoidRootPart")
local clientGui = client:WaitForChild("PlayerGui")
local doorGui = client:WaitForChild("doorKick")

local box = doorGui:WaitForChild("box")
local button = box:WaitForChild("button")
local fill = box:WaitForChild("fill")

local kickEvent = game.ReplicatedStorage:WaitForChild("onKick")
local mouse = client:GetMouse()

-- TWEENS --

local ti = TweenInfo.new(12, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)

local fillTween = ts:Create(fill, ti,{Position = UDim2.new(0.5, 0, 0.5, 0)})

local door

-- UserInputService --

uis.InputBegan:Connect(function(inp, gpe)
	
	if gpe then
		return
	end
	if (inp.KeyCode == Enum.KeyCode[button.Text]) then
		door = mouse.Target
		
		if not (door ~= nil) then return end
		if ((root.Position - door.Position).Magnitude > doorGui.MaxDistance) then return end
		
		if (cs:HasTag(door, "Door")) then
			print("Instance is a door")
			
			fillTween:Play()
		end
	end	
		
end)

I would appreciate any help. Thanks

You misspelled HumanoidRootPart.

Bit of an awkward moment.

1 Like

Oh wow… Kinda embarrassing. Thanks for the help :grimacing:

It might have been a spelling mistake in the topic. But if you did not make a spelling mistake then consider switching WaitForChild() to FindFirstChild().

1 Like

Not Exactly

WaitForChild actually waits until a certain item exists,
Which is why it gives the warning:

Infinite yield possible for...

FindFirstChild looks for the Item, if its not found, it will return nil and will error when used unless called upon again

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.