So I put a message box after the IniWrite() and it never popped up when I clicked save. So that means the code is never even reaching that line.
I replaced the "Save" bar button with a regular button and it reaches the line, but $X[5] exceeds the variable's array range, which means $X's array is smaller than 5. I changed the number to 2 and it worked.
EDIT: Here is your edited code:
#include
#include
#include
#include
#include
#include
#include
#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("Form1_1", 170, 135, 222, 464)
;$Save = GUICtrlCreateMenu("Save")
$Save = GUICtrlCreateButton("TEST", 10, 10, 30, 30)
$hX = GUICtrlCreateInput("pos[0]", 16, 16, 49, 21)
$hY = GUICtrlCreateInput("pos[1]", 104, 16, 49, 21)
$MouseCoordX = GUICtrlCreateInput("-1", 16, 96, 49, 21)
$MouseCoordY = GUICtrlCreateInput("-1", 104, 96, 49, 21)
$N = GUICtrlCreateInput("1", 64, 56, 33, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;pre-declare x & y
local $X[5]
local $Y[5]
;pre-declare end
HotKeySet("{SPACE}", "Var")
While 1
$nSet = GUICtrlRead($N)
$pos = MouseGetPos()
GUICtrlSetData($hX, $pos[0])
GUICtrlSetData($hY, $pos[1])
If $nSet > 0 then
GUICtrlSetData($MouseCoordX, $x[$nSet])
GUICtrlSetData($MouseCoordY, $y[$nSet])
EndIf
$Msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
fileDelete(@tempDir & "\image9.jpg")
ExitLoop
Exit
Case $msg = $Save
IniWrite("Vars.ini", "Variables", "X", $X[2])
MsgBox(64, "TEST", "MADE IT HERE")
EndSelect
WEnd
Func Var()
If $nSet > 0 then
$x[$nSet] = $pos[0]
$y[$nSet] = $pos[1]
GUICtrlSetData($N, $nSet + 1)
EndIf
EndFunc