You have a few issues here:
- You cannot directly use story or temporary variables within the <<script>> macro as it only accepts pure JavaScript. To directly use story or temporary variables you'd need something which accepts TwineScript, like <<run>>.
- You cannot use <Array>.delete() to delete by indices as it deletes by value. To delete an array member(s) by indices you want <Array>.deleteAt().
There are multiple ways to accomplish your goal, however, the easiest thing to do would be to use <Array>.push() and <Array>.shift() to shift the first member off of the array and push it onto the end.
Here's an example which uses <<run>>:
<<link "change weapon">>
<<run $weapons.push($weapons.shift())>>
<<replace "#inv1">> $weapons[0].name<</replace>>
<<replace "#inv2">> $weapons[1].name<</replace>>
<<replace "#inv3">> $weapons[2].name<</replace>>
<<replace "#inv4">> $weapons[3].name<</replace>>
<<replace "#inv5">> $weapons[4].name<</replace>>
<</link>>
For bonus points, here's the same example but using <<script>>, just to show how you'd access story variables in JavaScript: (see: State.variables)
<<link "change weapon">>
<<script>>
var sv = State.variables;
sv.weapons.push(sv.weapons.shift());
<</script>>
<<replace "#inv1">> $weapons[0].name<</replace>>
<<replace "#inv2">> $weapons[1].name<</replace>>
<<replace "#inv3">> $weapons[2].name<</replace>>
<<replace "#inv4">> $weapons[3].name<</replace>>
<<replace "#inv5">> $weapons[4].name<</replace>>
<</link>>