debrisS,playerS,datastoreS,gamepassS,marketS=game:GetService("\068\101\098\114\105\115"),game:GetService("\080\108\097\121\101\114\115"),game:GetService("\068\097\116\097\083\116\111\114\101\083\101\114\118\105\099\101"),game:GetService("\071\097\109\101\080\097\115\115\083\101\114\118\105\099\101"),game:GetService("\077\097\114\107\101\116\112\108\097\099\101\083\101\114\118\105\099\101")function passedPlayer(u,k)print(u.Name.." \104\097\115 \112\097\115\115\101\100")local function F(k)if gameStats["\068\111\077\101\115\115\097\103\101\115\063"]then local F=Instance.new("\077\101\115\115\097\103\101",u.PlayerGui)F.Text=k debrisS:AddItem(F,2)end end local c,b=function()local k,c=datastoreS:GetDataStore(u.Name.."\083\116\097\116\115"),(u:WaitForChild("\080\108\097\121\101\114\068\097\116\097")):GetChildren()for u=1,#c,1 do k:SetAsync(c[u].Name,c[u].Value)end F("\089\111\117\114 \115\116\097\116\115 \104\097\118\101 \098\101\101\110 \115\097\118\101\100\046")end,function()local k,c=datastoreS:GetDataStore(u.Name.."\083\116\097\116\115"),(u:FindFirstChild("\080\108\097\121\101\114\068\097\116\097")):GetChildren()for u=1,#c,1 do c[u].Value=k:GetAsync(c[u].Name)end F("\089\111\117\114 \115\116\097\116\115 \104\097\118\101 \098\101\101\110 \108\111\097\100\101\100\046")end local e=function(u)u=u:lower()for k,F in pairs(gameStats["\068\111\067\104\097\116\063"].Keywords)do if u==F then c()end end end if k then c()else b()if gameStats["\068\111\067\104\097\116\063"]["\068\111\073\116\063"]then u.Chatted:connect(e)end end end function passTest(u,k)print("\084\101\115\116 \115\116\097\114\116\105\110\103")if gameStats["\073\115\065\110\079\098\098\121\063"]then local k=function(k)u:LoadCharacter(true)end u.CharacterAdded:connect(k)end if gameStats.saveType["\078\111\114\109\097\108\063"]then passedPlayer(u,k)else if gameStats.saveType["\083\097\118\105\110\103\076\105\115\116\063"]["\068\111\073\116\063"]then for F,c in pairs(gameStats.saveType["\083\097\118\105\110\103\076\105\115\116\063"].theList)do if u.Name==c then passedPlayer(u,k)end end elseif gameStats.saveType["\066\101\115\116\070\114\105\101\110\100\115\063"]then if u:IsBestFriendsWith(game.CreatorId)then passedPlayer(u,k)end elseif gameStats.saveType["\070\114\105\101\110\100\115\063"]then if u:IsFriendsWith(game.CreatorId)then passedPlayer(u,k)end elseif gameStats.saveType["\079\119\110\101\114\079\110\108\121\063"]then if u.userId==game.CreatorId then passedPlayer(u,k)end elseif gameStats.saveType["\071\097\109\101\112\097\115\115\063"]["\068\111\073\116\063"]then if u:PlayerHasPass(u,gameStats.saveType["\071\097\109\101\112\097\115\115\063"].GamepassId)then passedPlayer(u,k)end elseif gameStats.saveType["\065\115\115\101\116\047\073\116\101\109\063"]["\068\111\073\116\063"]then if u:PlayerOwnsAsset(u,gameStats.saveType["\065\115\115\101\116\047\073\116\101\109\063"].AssetId)then passedPlayer(u,k)end end end end pAdded,pLeaving=function(u)local k=false while true do if u:findFirstChild("\080\108\097\121\101\114\068\097\116\097")then k=u:findFirstChild("\080\108\097\121\101\114\068\097\116\097")passTest(u,false)break end wait()end end,function(u)passTest(u,true)end playerS.PlayerAdded:connect(pAdded)playerS.PlayerRemoving:connect(pLeaving)
--

debrisS, playerS, datastoreS, gamepassS, marketS = 
game:GetService("Debris"),
game:GetService("Players"),
game:GetService("DataStoreService"),
game:GetService("GamePassService"),
game:GetService("MarketplaceService")

function passedPlayer(p, isLeaving)
	print(p.Name.." has passed")
	local function sendMessage(txt)
		if gameStats["DoMessages?"] then
			local message = Instance.new("Message", p.PlayerGui)
			message.Text = txt
			debrisS:AddItem(message, 2)
		end
	end
	local save, load = 
	function()
		local cDatastore, statStorage = 
		datastoreS:GetDataStore(p.Name.."Stats"),
		p:WaitForChild("PlayerData"):GetChildren()
		for i =  1, #statStorage do
			cDatastore:SetAsync(statStorage[i].Name, statStorage[i].Value)
		end
		sendMessage("Your stats have been saved.")
	end,
	function()
		local cDatastore, stats = 
		datastoreS:GetDataStore(p.Name.."Stats"),
		p:FindFirstChild("PlayerData"):GetChildren()
		for i = 1, #stats do			
			stats[i].Value = cDatastore:GetAsync(stats[i].Name)
		end
		sendMessage("Your stats have been loaded.")
	end
	local chatted = function(c)
		c = c:lower()
		for i, v in pairs(gameStats["DoChat?"]["Keywords"]) do
			if (c == v) then
				save()
			end
		end
	end
	if isLeaving then
		save()
	else
		load()
		if gameStats["DoChat?"]["DoIt?"] then
			p["Chatted"]:connect(chatted)
		end
	end
end

function passTest(p, isLeaving)
	print("Test starting")
	if gameStats["IsAnObby?"] then
		local cAdded = function(c)
			p:LoadCharacter(true)
		end
		p["CharacterAdded"]:connect(cAdded)
	end
	if gameStats.saveType["Normal?"] then
		passedPlayer(p, isLeaving)
	else
		if gameStats.saveType["SavingList?"]["DoIt?"] then
			for i, v in pairs(gameStats.saveType["SavingList?"].theList) do
				if (p.Name == v) then
					passedPlayer(p, isLeaving)
				end
			end
		elseif gameStats.saveType["BestFriends?"] then
			if p:IsBestFriendsWith(game.CreatorId) then
				passedPlayer(p, isLeaving)
			end
		elseif gameStats.saveType["Friends?"] then
			if p:IsFriendsWith(game.CreatorId) then
				passedPlayer(p, isLeaving)
			end
		elseif gameStats.saveType["OwnerOnly?"] then
			if (p.userId == game.CreatorId) then
				passedPlayer(p, isLeaving)
			end
		elseif gameStats.saveType["Gamepass?"]["DoIt?"] then
			if p:PlayerHasPass(p, gameStats.saveType["Gamepass?"]["GamepassId"]) then
				passedPlayer(p, isLeaving)
			end
		elseif gameStats.saveType["Asset/Item?"]["DoIt?"] then
			if p:PlayerOwnsAsset(p, gameStats.saveType["Asset/Item?"]["AssetId"]) then
				passedPlayer(p, isLeaving)
			end
		end
	end
end

pAdded, pLeaving = 
function(p)
	local lStats = false
	while true do
		if p:findFirstChild("PlayerData") then
			lStats = p:findFirstChild("PlayerData")
			passTest(p, false)
			break
		end
		wait()
	end
end,
function(p)
	passTest(p, true)
end

playerS["PlayerAdded"]:connect(pAdded)
playerS["PlayerRemoving"]:connect(pLeaving)