How to detect if object exists?

I want to detect if player has bloxy cola in their inventory. I used this:

if player.Backpack:FindFirstChild("BloxyCola") == nil and character:FindFirstChild("BloxyCola") == nil then
	local clone = tool1:Clone()
	clone.Parent = player.Backpack
end

The weird part is that this script works perfectly fine in another script I have, but in this script it gets exhausted trying to find the bloxy cola for some reason.

Is only dont put the “== nil” to “if not player.Backpack (…)” and the next things

And to put the tool allways, is only put the tool to player.Backpack and player.StarterGear to never disappear (or put the tool on game.StarterPack in the studio)

if not player.Backpack:FindFirstChild("BloxyCola") and not character:FindFirstChild("BloxyCola") then
	local clone = tool1:Clone()
	clone.Parent = player.Backpack
end
1 Like

It worked, but I did not understand a word you said in the second part.

I’m saying:

After he have the item, if he dies or reset, the item disappear, to this dont happend you can make

if not player.Backpack:FindFirstChild("BloxyCola") and not character:FindFirstChild("BloxyCola") then
	local clone = tool1:Clone()
	clone.Parent = player.Backpack
    local clone = tool1:Clone()
	clone.Parent = player.StarterGear
end

Oh it’s okay. I have the script in a repeating loop so if they die the script will just immediately give it back to them.

Also I tried putting tools in starter gear before and it never worked.

Update: Well turns out we still have a problem. So basically the script still gets exhausted sometimes but the script still works for some reason after it gets exhausted.

Add a

wait()

in the start of the loop/loops

I did, and it just waits that amount of time and then it freezes the game for a little bit then returns an error saying it got exhausted but the script still works anyways.