--Graveyard---------------
--[[

--function PlayerStatManager:getTycoonPurchases(player)
--	local succes,data = pcall(function() 
--		local playerUserId = "Player_" .. player.UserId
--		return sessionData[playerUserId]["TycoonPurchases"]
--	end)
--	if succes == false then
--		warn("ERROR---------PlayerStatManager:getTycoonPurchases----------->")
--		print(data)
--		return nil
--	else
--		return data	
--	end
--end 
local function setupPlayerData(player)	
	local playerMoney = serverStorage:WaitForChild("PlayerMoney")
	local playerStats = playerMoney:FindFirstChild(player.Name)
	--Sometimes people have duplicate tycoon add e.g in core handler script
	--adds PlayerMoney to storage and number value with player name that holds the 
	--money value 
	if playerStats == nil then
		local plrStats = Instance.new("NumberValue",playerMoney)
		plrStats.Name = player.Name
		local isOwner = Instance.new("ObjectValue",plrStats)
		isOwner.Name = "OwnsTycoon"
	end
	local playerUserId = "Player_" .. player.UserId
 
	local success,data = pcall(function()
		return playerData:GetAsync(playerUserId)
	end)
	
	if success then
		if data then
			print("----------Money: ---------> "..data["Money"])

			sessionData[playerUserId] = data
			local playerMoneyChild = playerMoney:FindFirstChild(player.Name)
			if playerMoneyChild then
				playerMoneyChild.Value = playerMoneyChild.Value + data["Money"]
			else
				print("------------playerMoneyChild is nil")
			end
		else
			print("No data----------------->")
			
			wait()
			local success,err = pcall(function()
				if player:IsInGroup(groupId) then
					local cashmoney = playerMoney:FindFirstChild(player.Name)
					if cashmoney then
						cashmoney.Value = cashmoney.Value + cashGivenAmount
					end
				end
			end)
			
			if success == false then
				print(err)
			end
			
			sessionData[playerUserId] = {}
			--Adding purchases names to player saves but false
			for f = 1,#savedPurchasesNames,1 do
				local name = savedPurchasesNames[f]
				sessionData[playerUserId][name] = false
			end
			
			sessionData[playerUserId]["Money"] = cashGivenAmount
			sessionData[playerUserId]["RebirthCount"] = 0
			return
		end

		--Adding new version objects
		for e = 1,#savedPurchasesNames,1 do
			local name = savedPurchasesNames[e]
			print("Name of object: ",name)
			if sessionData[playerUserId][name] == nil then
				print("Adding new version objects "..name)
				sessionData[playerUserId][name] = false
			end
		end]
		
	else
		warn("Couldn't get data")
		print(data)
	end		
end
]]
--

		--Testing wait TODO remove
		--TODO fix problem PurchaseHandlerNew add objects from purchases while it is being
		--required below and the it doesn't add new version for player if he joins the first initiolization
		--of the server
		--wait(5)--delete later on --if must turn back on uncomment this
		--Investigate
		--local purchaseHandlerNew = waitForTycoonsPurchaseHandlerNew()
		--local Objects = require(purchaseHandlerNew)
		--print("Name of tycoon: ",tycoons[1].Name)
		--local Objects = require(tycoons[1]:WaitForChild("PurchaseHandlerNew"))
	   

		--Adding new version objects