How do i fix the following problems of items not clone and/or not saving?
01 | local Players = game:GetService( "Players" ) |
02 | local DataStoreService = game:GetService( "DataStoreService" ) |
03 | local ServerStorage = game:GetService( "ServerStorage" ) |
05 | local playerdata = DataStoreService:GetDataStore( "testdata" ) |
07 | local tools = ServerStorage.Tools |
08 | local inventories = ServerStorage.Inventories |
10 | Players.PlayerAdded:Connect( function (client) |
11 | local key = "client_" .. client.UserId |
13 | local err, su = pcall ( function () |
14 | inventory = playerdata:GetAsync(key) |
18 | inventory = playerdata:GetAsync(key) |
20 | print ( "Failed to get datastore" ) |
21 | script.Parent.SendError:Fire(client.UserId, client.Name, err) |
22 | game:GetService( "TeleportService" ):Teleport(*insert place id here*, client) |
25 | local inventory_folder = Instance.new( "Folder" ) |
26 | inventory_folder.Name = client.Name |
27 | inventory_folder.Parent = inventories |
29 | for _, name in ipairs (inventory or { } ) do |
30 | local tool = tools [ name ] |
32 | tool:Clone().Parent = client.Backpack |
33 | tool:Clone().Parent = inventory_folder |
37 | Players.PlayerRemoving:Connect( function (client) |
38 | local key = "client_" .. client.UserId |
40 | local bkey = "backup_" .. client.UserId |
41 | local inventory_folder = inventories [ client.Name ] |
43 | for _, item in ipairs (inventory_folder:GetChildren()) do |
44 | table.insert(tools, item.Name) |
46 | playerdata:UpdateAsync(key, function (prev) |
47 | playerdata:SetAsync(bkey, prev) |
51 | inventory_folder:Destroy() |
54 | local remote = game:GetService( "ReplicatedStorage" ).Buy |
56 | local ServerStorage = game:GetService( "ServerStorage" ) |
57 | local tools = ServerStorage.Tools |
58 | local inventories = ServerStorage.Inventories |
60 | remote.Event:Connect( function (client, request) |
61 | local inventory_folder = inventories [ client.Name ] |
62 | local tool = tools [ request ] |
63 | if inventory_folder:FindFirstChild(tool.Name) = = nil then |
64 | tool:Clone().Parent = client.Backpack |
65 | tool:Clone().Parent = inventory_folder |
basically the error function is supposed to report errors and send the player to a limbo housing, i need to clone the item to the players inventory and i cant clone and save the data even with manual cloning. I cant seem to identify the problems