I have been trying to figure out datastores for a long time, but when i try to save tools in the player it does not work and it does not give me an error when I test it, but the leaderstats datastore works fine.
This is the datastore script, its kinda long.
local DSS = game:GetService("DataStoreService")
local DS1 = DSS:GetDataStore("DS1")
local toolsDS = DSS:GetDataStore("toolsDS")
local toolsFolder = game.ServerStorage.Tools
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = leaderstats
coins.Value = 1000
local playerId = "Player_" .. player.UserId
local toolsSaved = toolsDS:GetAsync(playerId) or {}
for i, v in pairs(toolsSaved) do
if toolsFolder:FindFirstChild(toolsSaved) then
toolsFolder[v]:Clone().Parent = player.Backpack
toolsFolder[v]:Clone().Parent = player.StarterGear
end
end
player.CharacterRemoving:Connect(function(char)
char.Humanoid:UnequipTools()
end)
local data
local success, errormessage = pcall(function()
data = DS1:GetAsync(playerId, data)
end)
if success then
coins.Value = data
print("Data Successfully Saved")
else
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerId = "Player_".. player.UserId
local toolsOwned = {}
for i, v in pairs(player.StarterGear:GetChildren()) do
table.insert(toolsOwned, v.Name)
end
local success2, errormessage2 = pcall(function()
toolsDS:SetAsync(playerId, toolsOwned)
end)
if success2 then
print("Data Successfully Saved")
else
warn(errormessage2)
end
local data = player.leaderstats.Coins.Value
local success, errormessage = pcall(function()
DS1:SetAsync(playerId, data)
end)
if success then
print("Data Successfully Saved")
else
warn(errormessage)
end
end)