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
Thanks everyone Ill try it all out Ill respond if it doesnt work thanks for the support. @TheBrainy06 it didn’t work and @Sarturex857 it gives me this error ServerScriptService.InventorySaver:31: attempt to index nil with ‘Humanoid’ for this line of code plr.Character.Humanoid:UnequipTools()
When I tested my script before, it worked, but I don’t know what problem you have, what parts of the script did you modified?
I have modified Nothing (I know the folder must be name related I took care of that) the only thing that I did was replicate the tools folder twice one for rep storage and one for ss
Try replacing plr.Character.Humanoid:UnequipTools() with plr.Character:WaitForChild(“Humanoid”):UnequipTools() or something, I don’t know.
This gives me more errors I don’t think that was it.
Try this.
local DSS = game:GetService("DataStoreService")
local ToolStore = DSS:GetDataStore("ToolStore")
local AllTools = game.ServerStorage.AllTools -- Reference to every tool in the game, but every tool you want obtainable in this folder
game.Players.PlayerAdded:Connect(function(plr)
local data = ToolStore:GetAsync(plr.UserId) -- Get Player's saved tools
if not data then
ToolStore:SetAsync(plr.UserId, {
-- Put the names of any default tools you want in here. It is a table.
})
end
if data then
for i, v in pairs(data) do
if AllTools:FindFirstChild(v) then
local newTool = AllTools:FindFirstChild(v):Clone() -- Clone tool
newTool.Parent = plr.Backpack -- Put cloned tool in Player's backpack
else
warn("Tool: "..v.." not found") -- Warn if tool is not found
end
end
end
plr.CharacterRemoving:Connect(function(char) -- It would save tools every time you die, if you don't want that you might have to add some additional code.
char.Humanoid:UnequipTools()
local saveTable = {}
for i, v in pairs(plr.Backpack:GetChildren()) do
if v:IsA("Tool") then
table.insert(saveTable, v.Name) -- Insert tool name into save table
end
end
ToolStore:SetAsync(plr.UserId, saveTable)
end)
end)
Saddly it didn’t work. Do you have anything to suggest?
How are you setting this up? I might just link a file to you and you can see how I’m doing it.
Its kinda faulty but I don’t really do this kind of stuff so try it a few times maybe you can fix it
Man maybe i aint ment for coding