-- Tycoon Module

local module = {}

module.money = script.Parent.Money
module.powers = script.Parent.Powers
module.crystals = script.Parent.Crystals

function module.init(Modules)
	local Sounds = Modules["Menu"]["sounds"]
	local Connections = {}
	local Player = game.Players.LocalPlayer
	local Tycoon = Player.PlayerTycoon.Value
	
	local function Unhook()
		for i,connection in pairs(Connections) do
			if connection.Connected then
				connection:Disconnect()
			end
			table.remove(Connections,i)
		end
	end

	local function Hook()
		Unhook()
		local Money = Player.MainData.Money
		local Powers = Player.MainData.Powers
		local Crystals = Player.MainData.Crystals
		table.insert(Connections,Powers.Changed:Connect(function()
			script.Parent.Powers.Value = Powers.Value
		end))
		table.insert(Connections,Crystals.Changed:Connect(function()
			script.Parent.Crystals.Value = Crystals.Value
		end))
		table.insert(Connections,Money.Changed:Connect(function()
			script.Parent.Money.Value = Money.Value
		end))
		script.Parent.Powers.Value = Powers.Value
		script.Parent.Crystals.Value = Crystals.Value
		script.Parent.Money.Value = Money.Value
	end
	Hook()
	Tycoon.Changed:Connect(Hook)
end

return module
