Make the Character not to move on the Z Axis [Locking Z Axis]

This may be the most banal Problem I ever had and it still doesnt leave me alone cuz I just cant fix it^^.

My Character Moves sometimes on the Z axis - its a sidescroller, so he shouldnt- sometimes when he collides with a stone or such, he slides arround it and… its really terrible.
I really tried 1000 ways like Colliders on the side or with rigidbode-freeze Position or even with a simple script

function Update () {
transform.position.z = 0;

but somehow everytime the character is still able to move on the Z Axis.

Specially with the Script I thought it worked but then after some time, magicly, he fell right through a plane like nothing even happend^^
It really anoyes me because it eats my Time and Im not able to work efficient till this problem is fixed, so please community help me out Thxx =)

The Script that I use to Controll my Player Edit fiddle - JSFiddle - Code Playground

I had that same problem. My player would slowly move itself around the object. I solved it by doing this:

var controller : CharacterController = GetComponent(CharacterController);

moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
controller.Move(moveDirection * Time.deltaTime);

moveDirection can be replaced with your variable. The second line of code is pretty much saying that moveDirection can move on the x axis, not the y, or the z however. I hoped this helped you.