Script not reading other script

I made a script that allows the player to level up their speed but it can’t read the movement script. The movement script I’m using is the sample assets beta First Person Character.

var level = 1;
var currentStamina : float = 100.0;
var maxStamina : int = 100;
var regenStamina : float = 2.0;
var drainStamina : float = 2.0;
var currentJump : float = 1.0;
var maxJump : float = 1.25;
var sprintSpeed : float = 8;
var strafeSpeed : float = 6;
var walkSpeed : float = 4;

private var playerScript : FirstPersonCharacter;

function Start()
{
	playerScript = GetComponent(FirstPersonCharacter);
}

function Update ()
{
	//if you're moving and pressing shift then speed up take from stamina bar
	if(controller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift))
	{
		currentStamina -= Time.deltaTime * drainStamina;
		playerScript.runSpeed = sprintSpeed;
	}
	
	//if not pressing anything, then normal movement speed
	else
	{
		playerScript.walkSpeed = walkSpeed;
	     playerScript.strafeSpeed = walkSpeed;
	}
	
	//Stamina Regeneration
	if(playerScript.walkSpeed == walkSpeed && (currentStamina >= 0))
	{
		currentStamina += Time.deltaTime * regenStamina;
	}
	
	//if moving, pressing shift and stamina is 0 then you cannot sprint
	if(Input.GetKey(KeyCode.LeftShift) && currentStamina <= 0)
	{
		playerScript.walkSpeed = walkSpeed;
	}
	
	//if stamina regeneration set to 100, never go past
	if(currentStamina >= maxStamina)
	{
		currentStamina = maxStamina;
	}
	
	//if goes to 0, then set to 0
	if(currentStamina <= 0)
	{
		currentStamina = 0;
	}
}

Hey,

I think that the error might be caused because you are trying to get a C# script in a JavaScript script. Try this:

var playerScript : MonoScript;

and you can assign it using:

playerScript = GetComponent(YourComponent);

or if it’s a C# script, you might need:

playerScript = GetComponent("YourComponent");

in your ‘Start()’ function, or you could just assign it manually in the inspector.

If you need further assistance or it didn’t work, feel free to ask. Oh and, sorry for any code errors. Visual Studio doesn’t seem to like JavaScript.

Best of luck,

SeeSharp.

If one of the scripts is C# and the other is Javascript they cannot reference each other if they are in the same folder in you assets folder. This has to do with compiling order so just move all your javascript or c# scripts to standard assets and leave the other outside of it. Plugin folder also works for this