Tool saving script fails to load/save data or clone tools into the backpack. What's wrong? [FIXED]
Asked by
5 years ago Edited 4 years ago
Script maybe doesn't successfully save data. It loads it in too (Maybe this is where it goes wrong), but the tools do not clone into the backpack. What is the problem?
01 | local dataStoreService = game:GetService( "DataStoreService" ) |
02 | local toolStore = dataStoreService:GetDataStore( "TOOLS" ) |
05 | game.Players.PlayerAdded:Connect( function (player) |
07 | local sucess, errormessage = pcall ( function () |
08 | data = toolStore:GetAsync(player.UserId) |
12 | for i,v in pairs (data) do |
13 | local tool = game:WaitForChild( "ReplicatedStorage" ).Tools:FindFirstChild(data [ i ] ) |
16 | tool:Clone().Parent = player.Backpack |
21 | warn( "Datastore error!" ) |
26 | game.Players.PlayerRemoving:Connect( function (player) |
27 | local toolsToSave = { } |
28 | for key, object in pairs (player.Backpack:GetChildren()) do |
29 | table.insert(toolsToSave, object.Name) |
31 | local sucess, errormessage = pcall ( function () |
32 | toolStore:SetAsync(player.UserId, toolsToSave) |
35 | print ( " ToolData Sucess!" ) |
36 | print (player.Name .. ",s data has been saved, its " , game:GetService( "HttpService" ):JSONEncode(toolsToSave)) |
38 | warn( "Datastore error!" ) |