local datastoreService = game:GetService("DataStoreService")
local playerTools = datastoreService:GetDataStore("PlayerTools")
local toolManager = game.ReplicatedStorage:WaitForChild("Tools")
local function playerjoined(plr)
repeat task.wait()
until plr.Character
task.wait(3)
local succes, inventory = pcall(function()
return playerTools:GetAsync(plr.UserId)
end)
for i, name in pairs(inventory) do
local tool = toolManager:FindFirstChild(name)
if tool then
local toolClone = tool:Clone()
toolClone.Parent = plr.Backpack
end
end
end
local function playerleft(plr)
local backpack = plr.Backpack
local char = plr.Character
local tools = {}
if char then
for i, tool in pairs(char:GetChildren()) do
if tool:IsA("Tool") then
table.insert(tools,tool.Name)
end
end
end
if backpack then
for i, tool in pairs(backpack:GetChildren()) do
if tool:IsA("Tool") then
table.insert(tools,tool.Name)
end
end
end
local succes, err = pcall(function()
return playerTools:SetAsync(plr.UserId,tools)
end)
if not succes then
warn(err)
end
end
game.Players.PlayerAdded:Connect(function(plr)
playerjoined(plr)
end)
game.Players.PlayerRemoving:Connect(function(plr)
playerleft(plr)
end)```
#tool saving dosent work
1 messages · Page 1 of 1 (latest)
that is not correct
you can basically save whatever you want just not userdata (Instances...)
local datastoreService = game:GetService("DataStoreService")
local playerTools = datastoreService:GetDataStore("PlayerTools")
local toolManager = game.ReplicatedStorage:WaitForChild("Tools")
local function playerjoined(plr)
repeat task.wait()
until plr.Character
task.wait(3)
local succes, inventory = pcall(function()
return string.split(playerTools:GetAsync(plr.UserId),":::")
end)
for i, name in inventory do -- pairs is so 2018
local tool = toolManager:FindFirstChild(name)
if tool then
local toolClone = tool:Clone()
toolClone.Parent = plr.Backpack
end
end
end
local function playerleft(plr)
local backpack = plr.Backpack
local char = plr.Character
local tools = ""
if char then
for i, tool in char:GetChildren() do
if tool:IsA("Tool") then
tools = tools .. tool.Name .. ":::"
end
end
end
if backpack then
for i, tool in backpack:GetChildren() do
if tool:IsA("Tool") then
tools = tools .. tool.Name .. ":::"
end
end
end
local succes, err = pcall(function()
return playerTools:SetAsync(plr.UserId,tools)
end)
if not succes then
warn(err)
end
end
game.Players.PlayerAdded:Connect(function(plr)
playerjoined(plr)
end)
game.Players.PlayerRemoving:Connect(function(plr)
playerleft(plr)
end)
really?
this os correct
that is not correct.
js use this
as you can see I saved a table, the only thing is that this get encoded in json and then decoded
it didnt work
honestly idk what to do
put player tool data into a table and then save the table
if your having issues uh
you need to just go through the needed properties of the tool
you might only need name
and then you can just
local tools = {};
for i, v in ipairs(player.Backpack:GetChildren()) --[[ipairs for order]] do
table.insert(tools, v.Name);
end```
rewrite your original code since you do smth like this
its prob an issue somewhere in your code so do a ton of debug prints
or smth
idk
use character removing instead of player removing
local datastoreService = game:GetService("DataStoreService")
local playerTools = datastoreService:GetDataStore("PlayerTools")
local toolManager = game.ReplicatedStorage:WaitForChild("Tools")
local function playerjoined(plr)
repeat task.wait()
until plr.Character
task.wait(3)
local succes, inventory = pcall(function()
return string.split(playerTools:GetAsync(plr.UserId),":::")
end)
for i, name in inventory do -- pairs is so 2018
local tool = toolManager:FindFirstChild(name)
if tool then
local toolClone = tool:Clone()
toolClone.Parent = plr.Backpack
end
end
end
local function playerleft(plr,char)
local backpack = plr.Backpack
local tools = ""
if char then
for i, tool in char:GetChildren() do
if tool:IsA("Tool") then
tools = tools .. tool.Name .. ":::"
end
end
end
if backpack then
for i, tool in backpack:GetChildren() do
if tool:IsA("Tool") then
tools = tools .. tool.Name .. ":::"
end
end
end
local succes, err = pcall(function()
return playerTools:SetAsync(plr.UserId,tools)
end)
if not succes then
warn(err)
end
end
game.Players.PlayerAdded:Connect(function(plr)
playerjoined(plr)
plr.CharacterRemoving:Connect(function(char)
playerleft(plr,char)
end)
end)
this must work
game:bindtoclose
Ill look into it
dosent work, I also get this error
if succes is false then inventory will be the error message.
honestly it feels not possible to save tools in any way