Why is the Tool Saving Script only saving the first item in the backpack and not the others?
So I am currently making an Obby. I have a shop GUI in which people can buy items if they have enough money.
P.S: This is a YT tutorial.
I have placed a script inside serverscriptservice which is as follows:
01 | local ds = game:GetService( "DataStoreService" ):GetDataStore( "ToolSavee" ) |
02 | game.Players.PlayerAdded:connect( function (plr) |
03 | local key = "id-" ..plr.userId |
05 | local tools = ds:GetAsync(key) |
07 | for i,v in pairs (tools) do |
08 | local tool = game.ServerStorage.Tools:FindFirstChild(v) |
10 | tool:Clone().Parent = plr:FindFirstChild( "Backpack" ) |
11 | tool:Clone().Parent = plr:FindFirstChild( "StarterGear" ) |
17 | game.Players.PlayerRemoving:connect( function (plr) |
18 | local key = "id-" ..plr.userId |
19 | local toolsToSave = { } |
20 | for i,v in pairs (plr.Backpack:GetChildren()) do |
22 | table.insert(toolsToSave,v.Name) |
25 | ds:SetAsync(key,toolsToSave) |
But the problem is that this script is only saving the first item which the player buys e.g. If there are 2 items in the shop, and the player has enough money to buy both of them, so the first item he will buy will be stored in the backpack and if he buys the second item, the second item will be given to him.
But when the player rejoins the game, only the item he bought first will be saved not the other item.
What is wrong in this script?
Please do help.
Thanks