If you have an error, it helps to copy the message out of the arma.rpt file rather than be a bit vague about what is going wrong.
The most likely reason this doesn't work is that you a) think it is a complete solution (it isn't) and/or b) are running it as SQS using exec command.
// Run from init.sqf/init.sqs with:
// [] execVM "respawnWithoutGear.sqf";
if (isDedicated) exitWith {}; // Dedi server doesn't have a player.
waitUntil { alive player };
if (player iskindOf "Civilian") exitWith {}; // Civilians don't get gear anyway.
player addEventHandler ["KILLED", {
[] spawn
{
// Wait for respawn.
waitUntil { alive player };
// Wait until the unit has its equipment reset after the respawn.
waitUntil { (count (weapons player)) > 0 };
removeAllWeapons player; // Remove weapons and magazines.
removeAllItems player; // Remove items like compass and map.
};
}];