DataStore is Not Wokring in my game

My DataStore Permissions are enabled, i tried everything, but it doesn’t work, the script is in the ServerScriptService. The Script is also enabled. Heres the code

local dataStoreService = game:GetService("DataStoreService")
local store = dataStoreService:GetDataStore("Test1")

function saveData(plr)
	local success, error = pcall(function()
		store:SetAsync(plr.UserId.."-cash", plr.leaderstats.Cash.Value)
		store:SetAsync(plr.UserId.."-days", plr.leaderstats.Days.Value)
		print("Saved Data")
	end)

end

game.Players.PlayerAdded:Connect(function(plr)
	local cashData
	local daysData     
	local success, error = pcall(function()
		cashData = store:GetAsync(plr.UserId.."-cash")
		daysData = store:GetAsync(plr.UserId.."-days")
	end)
	if error then warn(error) end
	if cashData then
		print(cashData)
		plr.leaderstats:WaitForChild("Cash").Value = cashData
	end
	if daysData then
		print(daysData)
		plr.leaderstats:WaitForChild("Days").Value = daysData
	end

end)
game.Players.PlayerRemoving:Connect(function(plr)
	
	saveData(plr)
end)
game:BindToClose(function()
	
	for i,plr in ipairs(game.Players:GetPlayers()) do
		saveData(plr)
		task.wait()
	end
end) 

Also the script is also a parent of a script that adds leaderstats, somebody help me pls

I would make the leaderstats in the same script so it does not cause an error, ex: ‘leaderstats is not a valid member of plr’

I tried this but it still not saved, my datastore is enabled, idk why my game doesnt work with data storage

Is there any errors when u leave the game? (To test, try and save in studio.)

Wait

DO not do this, instead, do

if not success then warn(error) return end

Still dosent work, I dont get errors for my output

Trying using this video to help you.
https://www.youtube.com/watch?v=H-cDbjd5-bs

If it is ran in studio & the game hasn’t released - that will definitely cause a bug, if so first make the game public and test in roblox and not roblox studio.

You have to use RemoteEvents PlayerRemoving Dosen’t Work
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function() --"Save stuff you already wrote" end)

If the data is saved on the client it will not work, also using remote events is generally not recommended due to exploiting reasons.