I have tried making a Datastore Script that saves a player’s tools. For some reason, the player’s tools don’t save. I tried using scripts from youtube hoping that they work. But the same problem occurs with those Scripts.
I also don’t get anything in my output.
(Yes I have “Enable Studio Access to API Services” Enabled)
Here is how far I got with my script:
local dss = game:GetService("DataStoreService")
local toolsDS = dss:GetDataStore("ToolsDatas")
local toolsFolder = game.ServerStorage.Tools
game.Players.PlayerAdded:Connect(function(plr)
local toolsSaved
local success, er = pcall(function(
toolsSaved = toolsDS:GetAsync(plr.UserId .. "-tools") or {}
end)
print(success)
print(toolsSaved)
for i, toolSaved in ipairs(toolsSaved) do
if toolsFolder:FindFirstChild(toolSaved) then
toolsFolder[toolSaved]:Clone().Parent = plr.Backpack
toolsFolder[toolSaved]:Clone().Parent = plr.StarterGear
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
plr.Character.Humanoid:UnequipTools()
local toolsOwned = {}
print(plr.Backpack:GetChildren())
for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do
table.insert(toolsOwned, toolInBackpack.Name)
end
print(toolsOwned)
local success, errormsg = pcall(function()
toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
end)
if success == false then
print(errormsg)
end
if errormsg then warn(errormsg) end
end)
I would be really happy if somebody could help me.