How do i fix "Infinite yield possible on..."

So i am making a pet system for my game, and when i try to delete a pet, it gives me two errors. However, i cannot see why the error is giving “BPet” instead of the pets name. Any help would be appreciated!
1st Error:

"Infinite yield possible on `Players.Noobzilla1207.OwnedPets:WaitForChild("BPet")' "

2nd Error:

"Infinite yield possible on `Players.Noobzilla1207.OwnedPets:WaitForChild("Pet")' "
deletePetEvent.OnServerEvent:Connect(function(Player,petName)
	local deletedPet,failedDeleting = pcall(function()
		Player.OwnedPets:WaitForChild(petName .. "Pet"):Destroy()
		Player.ActionValues.CurrentInventorySpace.Value -= 1
	end)
	if not deletedPet then
		warn(failedDeleting)
	end
end)

Thanks!

1 Like

You can try using FindFirstChild()
Or check if what you’re trying to find even exists

1 Like

i have done that. when i do, it gives me the error “ServerScriptService.NormalValues:328: attempt to index nil with ‘Destroy’”

1 Like

Then what you’re trying to find doesn’t exist, lol.

1 Like

it clearly does though
test - Roblox Studio 6_30_2023 5_19_16 PM

1 Like

I don’t see nothing called Pet or BPet my boy

1 Like

oh wait. i just realized i meant to say “Player.ActionValues.OwnedPets…” :sweat_smile:

2 Likes

sorry for the trouble everyone

1 Like

It is fine, next time try to check if the objects even exist when you encounter that error

1 Like

wait im so dumb. “OwnedPets” isnt even in action values. its in the player…

1 Like

so why is the script getting “BPet” instead of the pet’s name?

1 Like

what’s firing the event, because it seems that it’s just returning the petName as “B” rather than what it’s supposed to

1 Like

a local script in a gui somewhere. i can get it if you need it.

can i see the script because im assuming it’s just sending the wrong thing to the server

1 Like
petImg.petImage.Activated:Connect(function()
						if deleteDebounce == false and toggleDelete.deleting.Value == true and petImg.equipped.Value == false and petImg:FindFirstChild('CrossMark') then
							deleteDebounce = true
							script:FindFirstChild("PaperSound"):Play()
							game:GetService('ReplicatedStorage').ServerEvents.deletePet:FireServer(petImg.Name)
							petImg:Destroy()
							wait(0.4)
							deleteDebounce = false
						end
					end)
				end
			end

(theres more if you need it)

2 Likes

:WaitForChild(item, math.huge) fixes this.

is the petImg name set to the correct thing because it looks like it’s just sending over the letter B rather than an actual pet name that’s stored in the player

Do you set the name to petImg? If you do can you show me the section of the code where it does.

for _, petImg in pairs(petListFrame:GetChildren()) do
				if petImg:IsA("ImageLabel") then
					if petImg.equipped.Value == true then

No could you share a part of the code where you set petImg.Name to something, the problem should be there

1 Like