I don't know if this will overwrite other player's data

  1. I want the data to be saved every 60 seconds (3 seconds for this e.g). If there are lots of players in the game at once, I don’t know whether this system will overwrite other player’s data.

  2. In theory I think it should work because what I’ve written here is a loop that will check all current players that are in the game and storing it into the database.

local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetOrderedDataStore("dataStore")

while wait(3) do
	for i,player in pairs(game.Players:GetPlayers()) do
		local playerID = player.UserId
		local data = player.leaderstats.Jump
		dataStore:SetAsync(playerID, data.Value)
		warn("Saved data for "..playerID)
	end
end

I would suggest using a pcall functions when using the DataStore service.

local success,message = pcall(function()
  return dataStore:SetAsync()
end)

pcall stands for protected call.
This adds a layer of safety, as well making it easy to check whether or not it successfully saved the players data.
If success returns false, their data failed to save, and message will provide an explenation/error code.

if success then
  print("Data saved!", playerID)
else
  print("Data did not save.", message, playerID)
end

I would also suggest that you use PlayerAdded event.

local function PlayerAdded(player)
  --From here you can start saving data for this player, remember to check if they are still in the game
end

game.Players.PlayerAdded:Connect(PlayerAdded)

This uses the event of PlayerAdded, through the game service Players which also contains the list of players in the server. It then connects to a function that I have called PlayerAdded as well. This event automatically puts through the player to the function.

With this setup, you can be sure that code written or functions activated, only run for the player that just joined the server, and not shared for all players. If any issues arrives with a player, or something else fails, it won’t interrupt a loop and cause issues for other players, it’s isolated to each player.
Theoretically this is also better, as it doesn’t “spam” Roblox’s servers with data saving for each player at once, so you’re not drowning Roblox with a lot of data saving at once, if you base the timing/loop from when they joined, rather than being synced with all players.

Hi MineJulRBX,

Thank you for your response. I created this so that if there is any case of server shutting down unexpectedly at least the data will be there (if the autosave just went passed).