How do i write to a datastore from within studio and have it actually save?

local DS = game:GetService("DataStoreService"):GetDataStore("PlayerStats")
game.Players.PlayerAdded:Connect(function(plr)
local Items = Instance.new("Folder",plr)
local leader = Instance.new("Folder",plr)
Items.Name = "Items"
leader.Name = "leaderstats"
local Item1 = Instance.new("IntValue",Items)
Item1.Name = "NewItem"
local ItemsKey = DS:GetAsync(plr.UserId.."-Items")
local Moners = Instance.new("IntValue",leader)
Moners.Name = "Cash"
local MoneyKey = DS:GetAsync(plr.UserId.."-Cash")
if ItemsKey ~= nil then
	for i,v in pairs(ItemsKey) do
		i.Parent = Items
	end
else	
end
if MoneyKey ~= nil then
	Moners.Value = Moners
else 
	Moners.Value = 500
end
end)

game.Players.PlayerRemoving:Connect(function(plr)
local j = 1
local items = {}
local Childs = plr.Items:GetChildren()
local Moners = plr.leaderstats.Cash
for i,v in pairs(Childs) do
	table.insert(items,j,i)
	j = j + 1
end
DS:SetAsync(plr.UserId.."-Items", items)
DS:SetAsync(plr.UserId.."-Cash", Moners.Value)
end)

I have been attempting to do some work with datastores for the sake of an inventory system and I have 0 clue how to actually write to the datastore from within studio for it does not ever seem to save.

The best you can do is enable API services in studio, however, if you only save data during the Players.PlayerRemoving event, it won’t save and it will find the plr as nil because in studio, after you click stop testing there is no time before the studio test server shuts down, not giving the script a chance to save data. However, if you were to do this in-game, it would work because there is a little bit of time before the server shuts down.

I found a solution based off of this, I just ran a local server and left while the servers till ran, thank you for the help!