The code:
local Datastore = game:GetService("DataStoreService")
local mainStore = Datastore:GetDataStore("Main")
local function saveData(player)
local dataToSave = {
Inventory = {},
Stats = {},
Locker = {}
}
for _, item in pairs(player.Backpack:GetChildren()) do
if item:IsA("Tool") then
table.insert(dataToSave.Inventory, item.Name)
end
end
-- Save the characters equipped tool before they leave
if player.Character and player.Character:FindFirstChildOfClass("Tool") then
table.insert(dataToSave.Inventory, player.Character:FindFirstChildOfClass("Tool").Name)
end
print(dataToSave)
end
local function loadData(player)
end
game.Players.PlayerAdded:Connect(loadData)
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end)
My issue:
I’m trying to add the player’s equipped tool to Inventory = {} before they leave, but im not sure on how to do that… Any suggestions?