--------------------- PLEASE DO NOT EDIT BELOW!!!



















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
