Not writing to file correctly

Hi,
I want the code to write PlayerNameFinal and count to an array in leaderboard.txt when SaveScoreButton is pressed.

This is currently what is being written to the file: System.Collections.Generic.Dictionary`2[System.String,System.Int32]

Code:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Vexe.FastSave;
using Vexe.Runtime.Types;

public class GUI_Button : MonoBehaviour {

public PlayerMovement GUIScript;
public RandomSpawn GUIScript1;
private int count = RandomSpawn.count;
public string PlayerName = "Enter name";
public string fileName = "leaderboard.txt";
string[] PlayerAndScore = new string [1];
public string PlayerNameFinal;
public string count1 = "";
private bool SaveScoreButton = false;

void OnGUI ()
{
	if (PlayerMovement.livess <= 0) 
	{
		GUI.Button (new Rect (400, 200, 300, 200), "Score:" + (count+10));
		PlayerName = GUI.TextField (new Rect (400, 400, 300, 100), PlayerName);
		SaveScoreButton = GUI.Button (new Rect (400, 500, 200, 100), "Save Score");
		CountToString ();
	}
}
void OnClick()
{
	PlayerNameFinal = PlayerName;
}
void Start()
{
	PlayerAndScore [0] = PlayerNameFinal;
	PlayerAndScore [1] = count1;
	System.IO.File.WriteAllLines(@"Desktop\Pixel Ninjav3.3\Assets\leaderboard.txt", PlayerAndScore);
}
void CountToString ()
{
	count1 = count.ToString();
}

}

This code is strange.

For one, you declare a string of length 1 at the top, and then you add 2 strings to the array. This code should throw an IndexOutOfBoundsException before it even gets to the IO call.

Perhaps try fixing the size of your PlayerAndScore array to:

string[] PlayerAndScore = new string[2];

Although I’m not sure how much that will help you, as I’m totally boggled as to how you get an output in the first place.

@Brocccoli thank you for all your help. really.

I have the command set on the save game button. upon it being pressed, the array is written to the file.

THANK YOU SO MUCH