I'm trying to make a data store system but for some reason it's behaving very weirdly, this is my code
check = function()
if #game:GetService("Players"):GetPlayers() == 1 then
return false
else
return true
end
end
game.Players.PlayerRemoving:Connect(function(player)
if check() then
local invInfo = {}
for _, tool in pairs(player.Backpack:GetChildren()) do
print("WERE HERE")
if tool:IsA("Tool") then
if tool:GetAttribute("Type") then
local name = tool:GetAttribute("Type")
local quality = tool:GetAttribute("Quality")
local size = tool:GetAttribute("Size")
table.insert(invInfo, {quality, size, tool.Value.Value, name})
end
end
end
pcall(function()
invStore:SetAsync(player.UserId, invInfo)
end)
local money = player.leaderstats.Money.Value
pcall(function()
moneyStore:SetAsync(player.UserId, money)
end)
end
end)
--
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
local invInfo = {}
for _, tool in pairs(player.Backpack:GetChildren()) do
if tool:IsA("Tool") then
if tool:GetAttribute("Type") then
local name = tool:GetAttribute("Type")
local quality = tool:GetAttribute("Quality")
local size = tool:GetAttribute("Size")
table.insert(invInfo, {quality, size, tool.Value.Value, name})
end
end
end
pcall(function()
invStore:SetAsync(player.UserId, invInfo)
end)
local money = player.leaderstats.Money.Value
pcall(function()
moneyStore:SetAsync(player.UserId, money)
end)
end
end)```