Make sure no values are nil, so I recommend printing ToolFolder, Backpack, and StarterPack before the loop through ToolData, and make sure ToolData is not nil either
When I printed tool folder I got nil does that help you?
You need to reference ToolFolder properly. Check it’s directory to see if it’s there
Im kind of a noob could you elaborate on that please?
So I see that when you set the value ToolFolder you do
game:GetService(“ServerStorage”):WaitForChild(“SavedTools”)
Check ServerStorage and see if the folder SavedTools is there, if it isn’t add one
Well it should work now. Try it and if it works please mark me as solution.
Then it’s something else with your code. I can’t help any further right now so either you’re gonna have to figure it out yourself or have someone else help sorry.
Are you still having problems or is it fixed?
Could you mention or check what exactly is inside ToolData
?
He puts the name of every tool on the player inside the ToolData
Still the same error sadly, I might give up
Which error? thought the ToolFolder one was fixed
Why did you separate this 2 functions?
No errors by error I meant it doesn’t work.
When you load the data from the datastore to the player backpack also clone it and put it into toolFolder
So, I made kind of the same system but with bools, I’ve made some changes in my script, and now it can save tools.
local Savings = game:GetService('DataStoreService'):GetDataStore('Tools')
local RS = game:GetService('ReplicatedStorage')
local tools = RS.Tools -- you can change this, type the ubication of the folder that contains your tools
local data
local tabb = {}
game.Players.PlayerAdded:Connect(function(plr)
--give data
local s, e = pcall(function()
data = Savings:GetAsync(plr.UserId)
for i, v in pairs(tools:GetChildren()) do
if data ~= nil then
local cloned_tool = tools:FindFirstChild(data[v.Name]):Clone()
cloned_tool.Parent = plr.Backpack
end
end
end)
if not s then
print(e)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
--save data
local tools = plr.Backpack
plr.Character.Humanoid:UnequipTools()
local s, e = pcall(function()
for i, v in pairs(tools:GetChildren()) do
tabb[v.Name] = v.Name
end
Savings:SetAsync(plr.UserId, tabb)
end)
if not s then
warn(e)
end
end)
Replace this line with
ToolData = SaveData:GetAsync(Player.UserId) or {}
I also don’t see that the data is being saved. If you are planning to save this tool table, make sure to JSONEncode it before saving and JSONDecode it before passing it into the for loop