I’ve made an obby and after finishing the obby you get a speed & gravity coil and I’m trying to make an inventory saving system but I’m having trouble making it work. It does not show any error, but it does not save it also. I’ve used this tutorial but idk what I’m doing wrong: How to save your players' inventory items - #2 by skarz19
I’ve put this script in ServerScriptService:
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.Tools
local inventories = ServerStorage.Inventories
Players.PlayerAdded:Connect(function(client)
local key = "client_" .. client.UserId
local inventory = player_data:GetAsync(key) -- Not worrying about pcalls, do that yourself
local inventory_folder = Instance.new("Folder")
inventory_folder.Name = client.Name
inventory_folder.Parent = inventories
wait(10)
for _, name in ipairs(inventory or { }) do
local tool = tool[name]
tool:Clone().Parent = client.Backpack -- For the player to use
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)
I’ve also made “Inventory” and “Tools” folders in ServerStorage, and I did put the coil inside the “Tools” folder. But still does not work… Anyone willing to help?