I have followed this tutorial on youtube on tools with datastores, and it's not working for me. It just doesn't save my tools when I open up the game. My Code: game.Players.PlayerAdded:Connect(function(player)
local key = "id-"..player.userId
pcall(function()
local tools = DataStore:GetAsync(key)
if tools then
for i,v in pairs(tools) do
local tool = game.ServerStorage.Tools:FindFirstChild(v)
if tool then
tool:Clone().Parent = player:WaitForChild("Backpack")
tool:Clone().Parent = player:WaitForChild("StarterGear")
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = "id-"..player.userId
pcall(function()
local toolsToSave = {}
player.Character.Humanoid:UnequipTools()
for i,v in pairs(player.Backpack:GetChildren()) do
if v then
table.insert(toolsToSave,v.Name)
end
end
DataStore:SetAsync(key, toolsToSave)
end)
end)

1 comment
I don't know what's wrong, but I think you should put an autosave, for game crashes, for example.