So I’ve made a script that blocks, duplicating items in player’s inventory, but when I try to :Destroy() the item, it prints:
Something unexpectedly tried to set the parent of item to NULL while trying to set the parent of item. Current parent is Backpack.
Script:
local Players = game:GetService("Players")
local counter = 0
function playerAdded(player)
player.CharacterAdded:Connect(function()
local backpack = player:WaitForChild("Backpack")
backpack.ChildAdded:Connect(function(item)
counter = 0
for i,v in pairs(player:GetDescendants()) do
if v.Name == item.Name then
counter += 1
if counter >= 2 then
item:Destroy()
print("Removed copy of: " .. item.Name)
end
end
end
end)
end)
end
Players.PlayerAdded:Connect(playerAdded)