I have a sell GUI and create a BoolValue inside of an item when it is sold and name it "flag" and set it to true. It is removing the item from the gui and giving the player the gold, but it is not removing the item from the players Backpack. I put a print inside the script to see if it is finding the item and it is. I look inside the players Backpack and the flag is on the item, but it is not finding the flag and removing the item.
local dataStore = require(game.ServerStorage.DataStore)
local RS = game:GetService("ReplicatedStorage")
local event = RS.Remotes:WaitForChild("Sell")
event.OnServerEvent:Connect(function(plr, amount)
plr.leaderstats.gold.Value = plr.leaderstats.gold.Value + amount
dataStore:AddStat(plr, "gold", amount)
for _, item in pairs(plr.Backpack:GetChildren()) do
print(item)
if item:FindFirstChild("flag") then
print("flag found")
plr.Backpack.item:Remove()
end
end
end)

3 comments
maybe try using :destroy() instead of :Remove() that may work but im not sure
I tried that already, but that didn't work either. Thanks though for answering. :)
also as a heads up: if the item is being held, it's found inside of their character instead of Backpack