#Optimizing Game With Modules

1 messages · Page 1 of 1 (latest)

hoary spade
#

Hi I am trying to optimize my game with modules on the client side.

I often need to access the player gui so I am constantly passing player as one of the parameters for my Init() function. Is this the right thing to do? I'm also initializing my variables in the init() function, is that fine?

This way seems to remind me of intializing vairables in a java constructor, which I like.

Please give me honest constructive feed back, thank you!

tame osprey
hoary spade
#

reference this pic

#

this is what my layout looks like

little reef
#

and initializing the variables in the init() function i think you have to do this only in variables that you have to update

#

this is not wrong but i don't think it is a good practice

#

especially when you need to use many variables in a code

#

you'll need to start one by one, and that will be unnecessary work in my opinion

hoary spade
eager flameBOT
#

studio** You are now Level 3! **studio

hoary spade
#

i’m passing the player because i need to access the player’s PlayerGui and the only reason i initialize the variables in the init() is because of an event listener might be created before the variables and instantiated

little reef
hoary spade
#

can i even run that on module scripts?

#

thought u can only use LocalPlayer on local scripts

little reef
#

if the module script is being called by localscripts yeah

hoary spade
#

oh fr

#

i didn’t know that

#

because it’s been required by a local script

little reef
#

yeah the modulescript can be localscript and normal script

#

it depends on where are you require them

hoary spade
#

oooooooh

#

that makes sense ty

tame osprey
slender stream
#

idk what your game is about but I will add this;
if for whatever reason you reset your character or your character dies you have to initiate the module scripts inside a CharacterAdded function again as modules can only be required once and you need to initiate some variables inside the CharacterAdded function again aswell due to the 'player.Character' not existing after resetting

#

plus - if you have :Connect functions inside the CharacterAdded function you must also disconnect those functions if your player resets as well. just use CharacterRemoving to disconnect them.. This is because nested :Connect functions will double fire if you don't disconnect them.