SO here is my code(With error):
------------------------------------
game.Players.PlayerAdded:connect(function(player)
local DataStore = game:GetService("DataStoreService"):GetDataStore(player.userId)
if player.Name ~= "Player" then
player:WaitForDataReady()
--Safely Load Data--
local AllTools = game.lighting:GetChildren()
local S1 = DataStore:GetAsync("Tools")
for i,v in pairs(AllTools) do
if v.Name == S1[i.Name] then -- attempt to index I (a Num Value)
v:Clone().Parent = player.Backpack
end
end
end
end)
game.Players.PlayerRemoving:connect(function(player)
game.OnClose = function()
pcall(function()
local DataStore = game:GetService("DataStoreService"):GetDataStore(player.userId)
local Tools = player.Backpack:GetChildren()
local s1 = {}
for i=1,#Tools do
if Tools[i].ClassName == "Tool" then
local n = i
s1[n] = Tools[i].Name
end
end
DataStore:SetAsync("Tools",s1)
end)
end
end)
---------------------------------------
SO the idea is that your tools save with data stores with the names being set as a string, then when they load back into the game it clones the tools from lighting, going through the table, then the tools in lighting. This is a simple sketch I whipped up but how would I get it to load the table back in? (around line 12 where the error is) And would this code necessarily save all tools? because if you have a tool equipped it goes to the player and not the backpack, how would I add that too? All help appreciated, Thx, Bubs

6 comments
thank you very much man! However my game is old and unfortunatly if all my tools were in a different parent the game would break, so instead of me spending hours fixing my game, is there a way where i can just check the class in a for loop for tools in lighting?
Yes there is, just use an if statment. It would be best to update the game though as this change would make it more efficient.
right okay,thanks man!
hmm it seems to be saving okay but not loading in :/ its throwing no errors
1st time it would not have any data to load.
i ran through with print errors and it seems to be line 24, the if statement doesnt seem to work :/ maybe its because its to do with lighting as the parent?