Hello I have a gun swich script that doesn't work can someone help me please?

Hi everyone,

I am making a FPS game but my Gun swich doesn’t work can someone help me please?

Here’s the script:

//change gun script

var First Weapon : Object;
var secondary Weapon : Object;

function Update: (){
  (Secondary Weapon)=false;
  (Secondary Weapon)=true;

if (Input.GetKeyDown(*2)){
  Play.Animation : Secondary Weapon.once;
  Play.Animation : First Weapon.once;

Thank you if you can help me with it :slight_smile:

var firstWeapon : Transform;
var secondaryWeapon : Transform;

function Update()
    else if(Input.GetKeyDown("2"))

There were sooooo many errors on this script. Ive managed to fix all the errors. Im going with the assumption that both guns are where they need to be in front of the character and do not have colliders attached. I just turn off the individual renderers, this is not the “real” way to do this but is much closer to the expected result you want.

Lets talk some basics now…

Variables DO NOT have spaces “first weapon” is not proper, firstWeapon is.

There is no " : " after a function name. Update: () is bad, Update() is proper.

When using a function that uses a string overload use quotation marks"", not asterisks**

An Object cannot be set to True or False. Only a boolean can be True or False (such as an if statement, which returns a boolean / Either True or False)

That covers the majority of errors i see…my suggestion is to Read The Scripting Ref found Here, and read up on proper javascript syntax. Hope this helps you with your coding

Thanks for that I will read that :smiley: