Tool saving script only loaded tools once? [FIXED]
Asked by
4 years ago Edited 4 years ago
So, I followed a yt tutorial on how to make a tool saving script. The first time I tried loading the tools it worked normally, but the 2nd time I played the game the script broke. Does anybody know how to fix this? Here's the script:
01 | local dss = game:GetService( "DataStoreService" ) |
02 | local toolsDS = dss:GetDataStore( "ToolsData" ) |
04 | local toolsFolder = game.ServerStorage.ToolsFolder |
06 | game.Players.PlayerAdded:Connect( function (plr) |
08 | local toolsSaved = toolsDS:GetAsync(plr.UserId .. "-tools" ) or { } |
10 | for i, toolSaved in pairs (toolsSaved) do |
12 | if toolsFolder:FindFirstChild(toolSaved) then |
14 | toolsFolder [ toolSaved ] :Clone().Parent = plr.Backpack |
15 | toolsFolder [ toolSaved ] :Clone().Parent = plr.StarterGear |
20 | plr.CharacterRemoving:Connect( function (char) |
22 | char.Humanoid:UnequipTools() |
27 | game.Players.PlayerRemoving:Connect( function (plr) |
31 | for i, toolInBackpack in pairs (plr.Backpack:GetChildren()) do |
33 | table.insert(toolsOwned, toolInBackpack.Name) |
36 | local success, errormsg = pcall ( function () |
38 | toolsDS:SetAsync(plr.UserId .. "-tools" , toolsOwned) |
40 | if errormsg then warn(errormsg) end |
43 | game:BindToClose( function () |
44 | local players = game.Players:GetPlayers() |
45 | for i = 1 , #players do |
46 | local plr = players [ i ] |
50 | for i, toolInBackpack in pairs (plr.Backpack:GetChildren()) do |
52 | table.insert(toolsOwned, toolInBackpack.Name) |
55 | local success, errormsg = pcall ( function () |
57 | toolsDS:SetAsync(plr.UserId .. "-tools" , toolsOwned) |
59 | if errormsg then warn(errormsg) end |
Also, I would like to address some common questions you may ask:
1. API Services are enabled.
2. I tested it both in studio and in the real game.
3. There are no errors in the output.
4. I can tell the problem is with loading the tools because when I stop the game in the output it says "DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 178628425-tools", meaning that it saved properly.
So if anybody could help I would really appreciate it!