Why this script dont work sometimes?

Sometimes when im joining this script dont work, and also not saving the value of levels?

local DS2 = require(game.ServerScriptService.Settings:WaitForChild("MainModule"))
DS2.Combine("MainKey", "WinsBackUp", "LevelBackUp")

game.Players.PlayerAdded:Connect(function(plr)
	local dataWins = DS2("WinsBackUp", plr)
	local dataLevel = DS2("LevelBackUp", plr)
	
	local folder = Instance.new("Folder", plr)
	folder.Name = "BackUpStats"
	
	local Wins = Instance.new("IntValue", folder)
	local Level = Instance.new("IntValue", folder)
	Wins.Name = "WinsBackUp"
	Level.Name = "LevelBackUp"
	
	if dataWins:Get() ~= nil then
		Wins.Value = dataWins:Get()
	else
		Wins.Value = 0
		if dataLevel:Get() ~= nil then
			Level.Value = dataLevel:Get()
		else
			Level.Value = 0
		end
		
		Wins.Changed:Connect(function()
			dataWins:Set(Wins.Value)
			
			
		Level.Changed:Connect(function()
			dataLevel:Set(Level.Value)
			end)
		end)
	end
end)

did you save the data? [data for the player who left first is not saved if you don’t save all player’s data, because ds2 use BindToClose]
is datastore in game settings enabled?

Yes. its enabled btw its my first time traferring to DS2 .

could be various things, do you have another “main module” in ServerScriptService.Settings

maybe it just isnt catching the first player that joins the game?
(player joined before script could start up)

No theres no second main module. also it dont save the data of levels unlike wins.

Alright i just fix this issue.

	if dataWins:Get() ~= nil then -- checks if datawins is not nill
		Wins.Value = dataWins:Get() 
	else
		Wins.Value = 0
		if dataLevel:Get() ~= nil then
			Level.Value = dataLevel:Get()
		else
			Level.Value = 0
		end
		
		Wins.Changed:Connect(function() -- these will only fire if datawins == "something" (they are inside the if loop)
			dataWins:Set(Wins.Value) 
			
			
		Level.Changed:Connect(function()
			dataLevel:Set(Level.Value)
			end)
		end)
	end
end)