Currently trying to check if an item from a player was deleted somehow and if so then remove it from the player’s gui, as a test im running it in a loop every 1 second but it would be much preferable if it was triggered only when an item from the player’s inventory was deleted
invEvent = game.ReplicatedStorage.InventoryEvent
plr = game:GetService('Players').LocalPlayer
inv = plr:FindFirstChild('Inventory')
parent = script.Parent
while task.wait(1) do
for i,child in pairs(inv:GetChildren()) do
for i,item in pairs(parent:GetChildren()) do
if child.Name ~= item.Name and item:IsA('TextButton') and item.Name ~= 'Sample' then
-- print(item.Name.." not found in "..plr.Name..' Inventory')
--item:Destroy()
print(child)
end
end
end
end
You could detect if a child is added or removed from the player’s backpack with an event.
Then if its removed from the backpack, check to make sure its not put under the character (meaning you are holding it)
If thats not the case, the item is removed.
script seems to work fine without using remote even since once its gone from the server its also gone from the client inventory, not the other way around of course, but i don’t think that will ever happen… so…
invEvent = game.ReplicatedStorage.InventoryEvent
plr = game:GetService('Players').LocalPlayer
inv = plr:FindFirstChild('Inventory')
parent = script.Parent
inv.ChildRemoved:Connect(function(child)
print(child.Name)
for i,item in pairs(parent:GetChildren()) do
if child.Name == item.Name and item:IsA('TextButton') and item.Name ~= 'Sample' then
item:Destroy()
end
end
end)