I made a script a while ago that saves the players tools when they leave the game and loads them back when the player enters the game. After I added filtering enabled to my game the script no longer works and for some reason it is breaking my leaderstats save script too. When I buy a weapon from the store, my coins goes down depending on how much I spent on the item. After rejoining the weapon is not saved and my coins are back to the way they were before i bought the item.
local Inventory = {}
local function Spawned(Char)
local Plr = game.Players:GetPlayerFromCharacter(Char)
for i,v in pairs(Inventory[Plr]) do
if Plr['Backpack']:findFirstChild(v.Name) then
Plr['Backpack'][v.Name]:Destroy()
end
v.Parent = Plr['Backpack']
end
Inventory[Plr] = {}
Char:WaitForChild('Humanoid').Died:connect(function()
for i,v in pairs({Plr['Backpack'], Char}) do
for ii,vv in pairs(v:GetChildren()) do
if vv:IsA('Tool') then
table.insert(Inventory[Plr], vv:Clone())
vv:Destroy()
end
end
end
end)
end
game.Players.PlayerAdded:connect(function(Plr)
Inventory[Plr] = {}
local Char = Plr.Character or Plr.CharacterAdded:wait()
Spawned(Char)
Plr.CharacterAdded:connect(Spawned)
end)
Also the leaderstats save on their own. So if I earn 20 coins in game they save, but not when I purchase an item.

2 comments
Also yes it is in a Local Script.
PlayerAdded is server side only, connect, :wait, :findFirstChild are deprecated, use Connect, Wait, FindFirstChild