Scripts are still running even after stopping studio playtest

I’m working with datastores for the first time and for a reason unknown to me the scripts are still running even after I stop studio playtest. I have two scripts in serverscriptservice, one that makes the stats go up, and another which saves said stats.
Here is the video:


Here is the leaderstats script:

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	local leaderstats = script.leaderstats:Clone()
	leaderstats.Parent = player
	
	while true do
		local seconds = leaderstats.TimeSpent
		seconds.Value += 1
		
		local level = leaderstats.Level
		level.Value = math.floor(seconds.Value/10)
		
		local prestige = leaderstats.Prestige
		prestige.Value = math.floor(seconds.Value/100)
		
		task.wait(1)
	end
end)

Here is the saving script:

local dataStoreService = game:GetService("DataStoreService")
local players = game:GetService("Players")

local playerStore = dataStoreService:GetDataStore("PlayerStats")

players.PlayerAdded:Connect(function(player)
	local leaderboard = player:WaitForChild("leaderstats")
	leaderboard.TimeSpent.Value = playerStore:GetAsync(player.Name .. "TimeSpent")
	leaderboard.TimeSpent.Changed:Connect(function()
		local success = pcall(function()
			playerStore:SetAsync(player.Name .. "TimeSpent", leaderboard.TimeSpent.Value)
			playerStore:SetAsync(player.Name .. "Level", leaderboard.Level.Value)
			playerStore:SetAsync(player.Name .. "Prestige", leaderboard.Prestige.Value)
		end)
		print(playerStore:GetAsync(player.Name .. "TimeSpent"))
	end)
end)

Please let me know what is the problem.

Theres a bigger problem! Scripts keep running even after the player leaves the game. I’m sure this has to do something with datastores.

stop the while loop that increments the TimeSpent
you can do that by save the connection, and disconnect it with PlayerRemoving
also not recommended to save those stats every TimeSpent changed. because there are limits to datastore requests.
you can do it once when PlayerRemoving