How can I change the maxForwardSpeed variable in the CharacterMotor script form a different script?

I’m trying to make a sprinting script but I can’t seem to figure out how to change that speed variable. I’ve tried changing the variable from inside the CharacterMotor script after spressing the shift key but nothing happens, that script confuses me.

Heres what I have. I’ve seen other questions like this but I still have not found my answer. With this script I get the error ‘maxForwardSpeed’ is nota member of ‘UnityEngine.Component’

var motorScript = transform.GetComponent("CharacterMotor");
var sprintSpeed = 15.0;

function Start () {

}

function Update () {

if(Input.GetKey(KeyCode.LeftShift)){
motorScript.maxForwardSpeed = sprintSpeed;
}

}

I don’t use JS, but judging from the error it thinks your “var motorScript” is of type Component, because GetComponent returns a Component type. If you explicitly declare motorScript as type CharacterMotor then you should be able to access CharacterMotor functions and variables. Try:

var motorScript : CharacterMotor;
motorScript = transform.GetComponent("CharacterMotor");