DataStore script not functioning

  1. What do you want to achieve? Keep it simple and clear!
    One value to save, this should be easy for me I don’t know why it isn’t working.
  2. What is the issue? Include screenshots / videos if possible!
    data prints as nil when joined
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("THEDATA")



game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local JBuck = Instance.new("IntValue")
	JBuck.Parent = leaderstats
	JBuck.Name = "JBuck"
	local PlayerUserId = "player"..player.UserId
	local data
	local success, err = pcall(function()
		data = ds:GetAsync(PlayerUserId)
	end)
	if success then 
		print(data)
		JBuck.Value = data
	else
		JBuck.Value = 0
	end
end)

game:BindToClose(function()
	for i, v in pairs(game.Players:GetChildren()) do
		local PlayerUserId = "player_"..v.UserId
		local data = v.leaderstats.JBuck.Value
		print(data)
		local success, err = pcall(function()
			ds:SetAsync(PlayerUserId, data)
		end)
		if success then
			print("Data stored")
		end
	end
end)

found your issue your data is being saved here "player_"..v.UserId but is calling on the data here "player"..player.UserId

oh wow, I didnt see that, thx…