How to access scripts with an object that has just been instantiated?

I’ve been playing around with various methods, but I’m having trouble, I was trying to use findwithtag but that didn’t work,

function OnTriggerEnter (collider : Collider) {
if (collider.gameObject.tag == ("tag")

collider.gameObject.GetComponent(script);
script.float = 2;
}

I also tried collider.gameObject.GetComponent() but that didn’t work either, if anyone can help thanks

Don’t name the parameter “collider”. Try renaming it to something else.

Same with float.

that was just an e.g. the actual looks like this

    function OnTriggerEnter (collider : Collider) {
    if (collider.gameObject.tag == ("1player"))

    var script2 : moveandjump = collider.gameObject.GetComponent(moveandjump);
    script2.speed = 2;
    }

I’m getting this error (
NullReferenceException: Object reference not set to an instance of an object
testno15.OnTriggerEnter)
on line 5

Its saying that I didn’t declare the object (script2) and yet I did it in the line before, whats going on? How do I fix this

Do it like this:
GetComponent();

Also - the instructions in your if statement aren’t wrapped in { } so it will only execute line 4 when the statement is true - therefore line 5 is always out of scope and doesn’t know what script2 is. Lastly - GetComponent will return null if there is no component of that type on the object.

I just tried that and it gave an error :
Assets/testno15.js(9,63): BCE0019: ‘GetComponentmoveandjump’ is not a member of ‘UnityEngine.GameObject’. Did you mean ‘GetComponent’?

No, leave the < and > around ScriptName.

thanks Kelso that fixed it, I’m gonna read some more about if and else statements now, I wasn’t aware of that, I thought it was just a shortcut to apply if you only got the if statement to excecute