Im trying to make a script that can save the tools that players gained during their journey i made this so far but is not working
local key = "keyg3n"
local players = game:GetService("Players")
game.Players.PlayerAdded:connect(function(loady)
local player = players:GetPlayerFromCharacter(loady)
local backpack = player.BackPack
loady:WaitForDataReady()
tools = loady:loadInstance(key..player.Name)
tools.Parent = backpack
end)
game.Players.PlayerRemoving:connect(function(savy)
local player = players:GetPlayerFromCharacter(savy)
local backpack = player.BackPack
local inventory = backpack:GetChildren()
savy:WaitForDataReady()
if inventory then
savy:saveInstance(key..player.Name)
end
end)
what is wrong on my script?
it is supposed to keep the tools that players gained whem they leave or die
NOTE: its my first time asking a question so im sorry for any mistake above

2 comments
there are no lines saying played added etc
ive replaced BackPack with Backpack but still nothing