-- We get the initial shop size for opening the shop frame.

local initialShopSize = shopFrame.Size

isOpen.Changed:Connect(function()
	if isOpen.Value == true then
		-- open

		shopFrame.Visible = true
		shopFrame.Size = UDim2.new(0,0,0,0)

		local shopTweenInfo = TweenInfo.new(0.15, Enum.EasingStyle.Linear)
		local shopTweenGoal = {
			Size = initialShopSize
		}

		local shopTween = ts:Create(shopFrame, shopTweenInfo, shopTweenGoal)
		shopTween:Play()
		shopBtn.TextLabel.Text = "Close Shop"
	elseif isOpen.Value == false then
		-- close

		local shopTweenInfo = TweenInfo.new(0.15, Enum.EasingStyle.Linear)
		local shopTweenGoal = {
			Size = UDim2.new(0,0,0,0)
		}

		local shopTween = ts:Create(shopFrame, shopTweenInfo, shopTweenGoal)
		shopTween:Play()
		-- When the Tween has finished, the shop frame is hidden.
		shopTween.Completed:Connect(function()
			shopFrame.Visible = false
			shopBtn.TextLabel.Text = "Buy Cash!"
		end)
	end
end)

shopBtn.MouseButton1Click:Connect(function()
	-- used to toggle the isOpen value to fire the Changed event.
	if isOpen.Value == true then
		isOpen.Value = false
	elseif isOpen.Value == false then
		isOpen.Value = true
	end
end)
