Why is infinite yield happening here?

Hello, I’m wondering why this piece of code produces an infinite yield?

I’m absolutely sure that the fishing rod is there, so it missing should not be a problem.
I’ve also noticed that adding a task.wait(1) before that at the start of the script fixes the problem.
Is it simply because the fishing rod is not loading fast enough?

try doing findfirstchild() first then waitforchild() after the or

I end up with this if I do that:

Try this, it should wait for the backpack and character and other items (it seems the backpack and character haven’t loaded for your script by that point)

local char = Player.Character or Player.CharacterAdded:Wait()
local backpack = Player:WaitForChild("Backpack", 10)

local fishingRod = backpack:WaitForChild("Fishing Rod Normal", 5) or char:WaitForChild("Fishing Rod Normal", 5)

if not fishingRod then
    warn("Fishing rod not found!")
end
2 Likes

That fixes it! Thanks! So I guess the problem was I wasn’t waiting for the backpack/character.

1 Like

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