so a while back i was scripting a raycasting gun system, and i got a script recommendation thing that prompted me to add a “:Part” to the “hit” variable which was the variable i used to detect what the raycast hit. i never checked out what it actually did, but i added it into the script and it seemed to work.
im just wondering if this is just to specify the type of instance? thnx!
its called typechecking, all it does tell the script editor what type a variable is. its completely useless functionally and is generally only used in some cases when autocomplete doesnt work correctly
No. Type-checking and annotiations are very helpful in terms of type-safety, aids you in many ways, and even encourages you to adopt programming patterns that benefit you and everyone else in the long run.
While the type-runtime does not interact or effect the main runtime generally, there are cases where type-checking actually makes your code faster, such as in native code generation. (number operations and vectors)
so, my assumption that the typechecking determined the type of class the variable is technically correct? and when should i use and not use typechecking?
You don’t need to use type-checking or annotations, the inference will automatically determine and refine the types for you, but if you want to be more strict with your types and get full auto-complete, and more type-safety, then you can use them.