Saving Data In Data Store Not Working

Not sure how I would be able to fix this.

local dataStoreService = game:GetService("DataStoreService")
local managementMinutes = dataStoreService:GetDataStore("ManagementACTIVITY")

game.Players.PlayerAdded:Connect(function(player)
	local shiftMinutes = 0
	local overallMinutes
	
	if not managementMinutes:GetAsync(player.Name) then
		managementMinutes:SetAsync(player.Name, 0)
	else
		overallMinutes = managementMinutes:GetAsync(0)
	end
	
	while wait(5) do
		shiftMinutes += 1
		overallMinutes += shiftMinutes
		shiftMinutes = 0
		managementMinutes:UpdateAsync(player.Name, overallMinutes)
		print(managementMinutes:GetAsync(player.Name, 0))
	end
end)

There’s so many issues with this script.

  1. Why are you putting player names as a key and not player ids?
  2. Why would you save a new player’s stats upon joining? What if there was a data corruption, or an error?
  3. In the line in the else statement, you’re literally loading someone’s stats that doesn’t even exist (as the :GetAsync() function loads the user’s data based on the key that you put in there), you can use managementMinutes:GetAsync(player.Name) or managementMinutes:SetAsync(player.Name)
  1. This won’t be executed in a minute so you’re not technically getting a shift minute
  2. You shouldn’t save a player’s stats too often, as that’s a bad scripting practice and can lose the player’s data.

Im not trying to demotivate you from scripting or anything, but maybe you should take an in-depth look at how data stores work here.

Also, how would I have multiple values for one single datastore.

By saving tables instead of the single values.
Something like this:

local Data = {
Money = player.leaderstats.money.value
Kills = player.leaderstats.kills.value
}
datastore:SetAsync(player.UserId, Data)

Im still new to the dev forum, and i have no clue on how to get that scripter tag next to your profile picture, but i have no clue how you have it with a script that bad (Sorry, just being honest here)

Like i said, take an in-depth look at how data stores work here.