Decreasing and increasing a SlowMotion powerup

I have created a very rudimentary slow motion ability in my game but I don’t want it to be able to be used at all times.

The solution I have in my head the idea is to have a SlowMotionCredit bank which depletes with usage at a fast rate and then slowly replenishes itself.

The following code is attached to the ‘player’ but once I add the SlowMotionCredit related lines the script compiles on but the slowmotion then doesn’t work… Interesting to hear people’s thoughts… cheers

var xspeed : float = 5; 
var zspeed : float = 5; 
var x : float; 
var z : float;

public var SlowMotionCredit : float = 60; // SlowMotionCredit Initial starting figure

function Update () { 

x = Input.GetAxis("Horizontal") * xspeed * Time.deltaTime; 
z = Input.GetAxis("Vertical") * zspeed * Time.deltaTime; 
transform.Translate(x, 0, z); 

SlowmotionCreditUpdate() {

 SlowMotionCredit +1; // replenish SlowMotionCredit at a rate of 1 per second
 
}
//SlowMotion Starts

if (Input.GetKeyDown ("space"))
    Time.timeScale=0.15;
    SlowMotionCredit - 12; // Deducting 12 Credits for each second of SlowMotion Time Spent
    
//Time resets
if (Input.GetKeyUp ("space"))
    Time.timeScale=1;
}

first off there is no {} on the

if (Input.GetKeyDown ("space"))
    Time.timeScale=0.15;
    SlowMotionCredit - 12; // D

So SlowMotionCredit -= 12 would get called every Update. What you need to do is change it to this

if (Input.GetKeyDown ("space") && SlowMotionCredit >= slowMoCost)// use a variable for cost that way its easy to edit
{
    Time.timeScale=0.15;
    SlowMotionCredit -= slowMoCost; // D
}

You should also add that to the Fixed update that way it lowers based off time and not how fast the FPS is