Hi, I was following a dataStore tutorial that is supposed to save the weapons the player owns. Whenever I join it doesn’t clone the items to my backpack nor do any errors show up in the output.
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")
local player_data = DataStoreService:GetDataStore("player_data")
local tools = ServerStorage.ShopItems
local inventories = ServerStorage.Inventories
Players.PlayerAdded:Connect(function(client)
local key = "client_"..client.UserId
local inventory = player_data:GetAsync(key)
local inventory_folder = Instance.new("Folder")
inventory_folder.Name = client.Name
inventory_folder.Parent = inventories
for _, name in ipairs(inventory or { }) do
local tool = tools[name]
tool:Clone().Parent = client.Backpack
tool:Clone().Parent = inventory_folder -- For saving and loading
end
end)
Players.PlayerRemoving:Connect(function(client)
local key = "client_".. client.UserId
local tools = {}
local inventory_folder = inventories[client.Name]
for _, item in ipairs(inventory_folder:GetChildren()) do
table.insert(tools, item.Name)
end
player_data:UpdateAsync(key, function(prev)
return tools
end)
inventory_folder:Destroy()
end)