I’m trying to code a script that gives you back the tools you had from the last run. It just don’t work for some reason.
I have tried the other way by getting the player’s tools right as they leave with all them BindToClose() stuff (I needed the BindToClose() because the game’s single-player). That also did not work. That is why I resorted to getting the player’s tools as they obtain them.
The Bank is a folder in ServerStorage that contains almost all tools that exist in the game, excluding the ones that I specifically don’t wanna be saved.
local service = game:GetService("DataStoreService")
local store = service:GetDataStore("toolsave")
local tools = {}
local bank = game.ServerStorage["tool bank"]
for _, plrs in pairs(game.Players:GetChildren()) do
if plrs:IsA("Player") then
char = plrs.CharacterAdded:Wait()
currentplayer = plrs
end
end
char.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
table.insert(tools, child.Name)
pcall(function()
store:SetAsync(tostring(currentplayer.UserId), tools)
end)
end
end)
game.Players.PlayerAdded:Connect(function(plr)
local char2 = plr.CharacterAdded:Wait()
local newtable = store:GetAsync(tostring(plr.UserId))
for _, newtool in pairs(newtable) do
local thechosenone = bank:FindFirstChild(newtool)
if thechosenone then
local clone = thechosenone:Clone()
clone.Parent = char2
end
end
end)