I have a tool load and save script inside ServerScriptService and as follows the script won't work.
local datastoreservice = game:GetService("DataStoreService")
local datastore = datastoreservice:GetDataStore("BackpackSave")
game.Players.PlayerAdded:Connect(function(player)
pcall(function()
local tool = datastore:GetAsync("User_"..player.UserId)
if tool then
for i,v in pairs(tool) do
local toolFound = game.ReplicatedStorage.Tools:FindFirstChild(v)
if toolFound then
toolFound:Clone().Parent = player.Backpack
toolFound:Clone().Parent = player.StarterGear
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
local toolsave = {}
for i, tool in pairs(player.Backpack:GetChildren()) do
if tool then
table.insert(toolsave,tool.Name)
end
end
datastore:SetAsync("User_"..player.UserId,toolsave)
end)
end)
What the script does is find tools inside a folder named Tools inside ReplicatedStorage and clone them and then save them inside their StarterGear, so the next time the player joins they will receive their tools. I, for some reason, can't find any errors here. API services are enabled.
Quick update: I have tried replacing a few things and it seems as if the search for the tool in replicatedstorage is thrown on an indefitnite yield.
local datastoreservice = game:GetService("DataStoreService")
local datastore = datastoreservice:GetDataStore("BackpackSave")
game.Players.PlayerAdded:Connect(function(player)
pcall(function()
print("Save script functions")
local tool = datastore:GetAsync("User_"..player.UserId)
if tool then
for i,v in pairs(tool) do
local toolFound = game.ReplicatedStorage.Tools:WaitForChild(v)
print(v)
if toolFound then
toolFound:Clone().Parent = player.Backpack
toolFound:Clone().Parent = player.StarterGear
print("Tools have saved!")
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
local toolsave = {}
for i, tool in pairs(player.Backpack:GetChildren()) do
if tool then
print("Tools have loaded!")
table.insert(toolsave,tool.Name)
end
end
datastore:SetAsync("User_"..player.UserId,toolsave)
end)
end)
The script is just stuck on the search for the tool, it has not printed to show that it has found the tool

2 comments
As I have already mentioned, my API services are enabled. I'll try removing that line of code though
This solution didn't work, unfortunately!