How would Datastore this?

Alright i have a script that gives +1 to a leaderboard titled “Minutes Played” but i cant find any script that saves it here is the script:

function onPlayerEntered(newPlayer)

	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local mins = Instance.new("IntValue")
	mins.Name = "Minutes Playing"
	mins.Value = 0


	mins.Parent = stats
	
	stats.Parent = newPlayer

	while true do
		wait(60)
		mins.Value = mins.Value + 1
	end
end



game.Players.ChildAdded:connect(onPlayerEntered)
1 Like

Try this thread:

It has tons of solutions.

1 Like

Alright, so i have the saving script now but the giving script no longer works, heres the script

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("GemSaveSystem")
local ds2 = datastore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(plr)
 local folder = Instance.new("Folder", plr)
 folder.Name = "leaderstats"
 local gems = Instance.new("IntValue", folder)
 gems.Name = "Minutes"
 local cash = Instance.new("IntValue", folder)
 cash.Name = "SP"
 
 gems.Value = ds1:GetAsync(plr.UserId) or 0
 ds1:SetAsync(plr.UserId, gems.Value)
 
 cash.Value = ds2:GetAsync(plr.UserId) or 0
 ds2:SetAsync(plr.UserId, cash.Value)
 
 gems.Changed:connect(function()
  ds1:SetAsync(plr.UserId, gems.Value)
 end)
 
 cash.Changed:connect(function()
  ds2:SetAsync(plr.UserId, cash.Value)
 end)
end)