How to Check if Cloned Things is In a Parent

What I want is when this remote event is fired, the given "orb"is cloned and parented to the player’s backpack once. However what happens is that when this remote event is fired, it constantly adds the cloned “orb” to the player’s backpack! Is there anyway to fix this – I tried adding a debounce where it only parents the cloned “orb” if the cloned orb isn’t in the player’s backpack but it doesn’t seem to be working. Thanks!

OrbGiveEvent.OnServerEvent:Connect(function(_, Orb)
	local toolClone = Orb:Clone()
	if table.find(Player.Backpack:GetChildren(), toolClone.Name) == nil then
		toolClone.Parent = _:FindFirstChildOfClass("Backpack")
	end
end)
1 Like

Use :FindFirstChild

orbGiveEvent.OnServerEvent:Connect(function(player, orb)
    if not player.Backpack:FindFirstChild('Orb') then
        orb:Clone().Parent = player.Backpack
    end
end)

It still constantly adds the cloned “orb” into the player’s backpack – though, I am trying to experiment your solution with an added while loop

You shouldn’t need a loop. Try this if the orb name can vary:

orbGiveEvent.OnServerEvent:Connect(function(player, orb)
    if not player.Backpack:FindFirstChild(orb.Name) then
        orb:Clone().Parent = player.Backpack
    end
end)
1 Like

Yo! The solution fixed it! Thanks dude!

1 Like