I dont know whay my script isnt saving the tools… please help if you spot an error
local toolstorage = game.ServerStorage
local blacklist = {"ClassicSword", "RocketLauncher"}
local data = game:GetService("DataStoreService"):GetDataStore("Player_Tools")
local players = game.Players
function savedata(plr)
local a = {}
for _, v in pairs(plr.StarterGear:GetChildren()) do
if table.find(blacklist, v.Name) then
else
table.insert(a, v.Name)
end
end
if a[1] then
data:SetAsync(plr.userId, a)
end
end
players.PlayerAdded:Connect(function(plr)
local b = data:GetAsync(plr.userId)
if b then
for _, v in pairs(b) do
toolstorage:FindFirstChild(v):Clone().Parent = plr.Backpack
toolstorage:FindFirstChild(v):Clone().Parent = plr.StarterGear
end
end
while true do
wait(300)
savedata(plr)
end
end)
players.PlayerRemoving:Connect(function(plr)
if plr then
savedata(plr)
end
end)
game:BindToClose(function()
for _, plr in pairs(players:GetChildren()) do
savedata(plr)
end
end)```
local toolstorage = game.ServerStorage
local blacklist = {"ClassicSword", "RocketLauncher"}
local data = game:GetService("DataStoreService"):GetDataStore("Player_Tools")
local players = game.Players
function savedata(plr)
local a = {}
for _, v in pairs(plr.Backpack:GetChildren()) do
if table.find(blacklist, v.Name) then
else
table.insert(a, v.Name)
end
end
if a[1] then
data:SetAsync(plr.userId, a)
end
end
players.PlayerAdded:Connect(function(plr)
local b = data:GetAsync(plr.userId)
if b then
for _, v in pairs(b) do
toolstorage:FindFirstChild(v):Clone().Parent = plr.Backpack
end
end
while true do
wait(300)
savedata(plr)
end
end)
players.PlayerRemoving:Connect(function(plr)
if plr then
savedata(plr)
end
end)
game:BindToClose(function()
for _, plr in pairs(players:GetChildren()) do
savedata(plr)
end
end)
Also please try sending the errors you’re getting so we can help you better!
Hope this will help
Answer 1, i moderatly know how to code.
Answer 2, me and my friend are making a game and he brought up this code to me, but since he doesnt have a roblox forums account to publish this with.
Hmm, ill have to refigure some stuff, so ill try another way todo this. All I wanted to do was make it so that i had a tool save system but had a blacklist. Thanks to whoever was kind enough to help!
I’m not sure if this is the problem, but I would try removing this autosave loop. I have no autosave feature (only PlayerRemoving) in my game and it saves data fine.
Changed a couple things and then found an output error coming from these lines… what is in your ServerStorage? The script expects the saved tools to also be in the ServerStorage.
local toolstorage = game.ServerStorage
local blacklist = {"ClassicSword", "RocketLauncher"}
local datastoreservice = game:GetService("DataStoreService")
local data = datastoreservice:GetDataStore("Player_Tools")
local players = game.Players
local function savedata(plr)
local a = {}
for _, v in pairs(plr.Backpack:GetChildren()) do
if table.find(blacklist, v.Name) then
else
table.insert(a, v.Name)
end
end
data:SetAsync(plr.userId, a)
print ("saved")
end
players.PlayerAdded:Connect(function(plr)
local b = data:GetAsync(plr.userId)
if b then
for _, v in pairs(b) do
toolstorage:FindFirstChild(v):Clone().Parent = plr.Backpack
toolstorage:FindFirstChild(v):Clone().Parent = plr.StarterGear
end
end
print ("loaded")
end)
players.PlayerRemoving:Connect(function(plr)
if plr then
savedata(plr)
end
end)
Putting the tool in the ServerStorage fixes it and makes the script work properly (saving and loading your tools!)