when you make datastores, would it be a good idea to use a system that stores every player’s userId in a table when the join the game, and then every five minutes or so, check through every player to see if their userid still exists, and if it doesn’t, then save the data and remove their userid from the table?
maybe something like this:
local Players = game:GetService("Players")
local dataTable = {}
Players.PlayerAdded:Connect(function(player)
table.insert (dataTable,1,player.UserId)
end)
while wait(300) do
local plrTable = Players:GetPlayers()
for a = 1, #dataTable do
for b = 1, #plrTable do
if plrTable[b].UserId == dataTable[a] then
-- if the player is still in the game --
break -- move on to the next spot in the data table
end
if b = #plrTable -- if it looped through to the last spot of the data table
if dataTable [a] ~= plrTable[#plrTable].UserId -- if it cannot find the last player's userId in the data table
-- save data here with that player's userid --
table.remove( dataTable, a )
end
end
end
end
end)
could it work? Is it a good way to save the data? I want to know because I might use it.