Hi guys im making a game and i want to save the inventory but it wont work theres no any errors on output
Script:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("myDataStore2")
local Players = game.Players
local ToolsFolder = game:GetService("ReplicatedStorage"):WaitForChild("Tools")
function PlayerAdded(plr)
local key = plr.UserId;
local Data;
local stdout, stderror = pcall(function()
Data = DataStore:GetAsync(key);
end)
if (Data ~= nil and type(Data) == "table") then
for i,v in next,Data do
if(ToolsFolder:FindFirstChild(v)) then
print(stdout, stderror)
ToolsFolder[v]:Clone().Parent = plr.Backpack;
end
end
end
print(stdout, stderror)
end
function PlayerRemoving(plr)
local Tools = {};
local key = plr.UserId;
for i,v in next,plr.Backpack:GetChildren() do
if (v:IsA("Tool")) then
table.insert(Tools,v.Name);
end
print("Error 30")
end
for i,v in next,plr.Character:GetChildren() do
if(v:IsA("Tool")) then
table.insert(Tools,v.Name)
end
end
local stdout, stderror = pcall(function()
DataStore:GetAsync(key.Tools)
end)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)
game:BindToClose(function()
for i,v in next,Players:GetChildren()do
PlayerRemoving(v)
end
end)

2 comments
Nope dont work on online
Let me edit my comment Zypsoh