local d=true local M=true local b=true local f={"\075\105\108\108\115"}local t={"\072\101\108\109\101\116";"\066\097\110\100\097\110\097";"\072\101\097\100\115\101\116";"\071\108\097\115\115\101\115";"\080\087"}game.Players.PlayerAdded:connect(function(b)wait()local v=(game:GetService("\068\097\116\097\083\116\111\114\101\083\101\114\118\105\099\101")):GetDataStore(b.userId)for d=1,#f,1 do v:UpdateAsync(f[d],function(d)return d or 0 end)end local w=Instance.new("\077\111\100\101\108",b)w.Name="\108\101\097\100\101\114\115\116\097\116\115"for d=1,#t,1 do S=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",w)S.Name=t[d]end for b=1,#f,1 do S=Instance.new("\078\117\109\098\101\114\086\097\108\117\101",w)S.Name=f[b]if d then S.Value=v:GetAsync(f[b])end if M then S.Changed:connect(function()v:SetAsync(f[b],S.Value)end)end end end)if b then game.Players.PlayerRemoving:connect(function(d)local M=(game:GetService("\068\097\116\097\083\116\111\114\101\083\101\114\118\105\099\101")):GetDataStore(d.userId)for b=1,#f,1 do stat=d.leaderstats:FindFirstChild(f[b])if stat then M:UpdateAsync(stat.Name,function(d)return stat.Value end)end end end)end



















local Auto_Load = true

local Auto_Save = true

local Save_On_Leave = true

local Stats = {"Kills"}

local StatsNotToSave = {"Helmet","Bandana","Headset","Glasses","PW"}



game.Players.PlayerAdded:connect(function(p)
	wait()
	local ODS = game:GetService("DataStoreService"):GetDataStore(p.userId)
	for i = 1,#Stats do
		ODS:UpdateAsync(Stats[i], function(old)
			return old or 0
		end)
	end
	local l = Instance.new("Model", p)
	l.Name = "leaderstats"
	for i = 1,#StatsNotToSave do
		S = Instance.new("StringValue", l)
		S.Name = StatsNotToSave[i]
	end
	for i = 1,#Stats do
		S = Instance.new("NumberValue", l)
		S.Name = Stats[i]
		if Auto_Load then
			S.Value = ODS:GetAsync(Stats[i])
		end
		if Auto_Save then
			S.Changed:connect(function()
				ODS:SetAsync(Stats[i], S.Value)
			end)
		end			
	end
end)

if Save_On_Leave then
	game.Players.PlayerRemoving:connect(function(p)
		local ODS = game:GetService("DataStoreService"):GetDataStore(p.userId)
		for i = 1,#Stats do
			stat = p.leaderstats:FindFirstChild(Stats[i]) 
			if stat then
				ODS:UpdateAsync(stat.Name, function(old)
					return stat.Value
				end)
			end
		end
	end)
end
