Is it best to have one PlayerAdded event in a script or multiple?


So in my obby game I control most things server-sided with one script., just over 100 lines. I want multiple things to happen when the player joins, so should I have different events for things or just use one for everything? Which is better for performance and optimization? Should I be using modules instead?

Thank you for your answers and have a wonderful day! :slight_smile:

1 Like

I think this should be in #help-and-feedback:code-review , but there isn’t really any noticeable difference between using multiple onevents for the same event. I’m not sure why you would want to use modules for something like that.

1 Like

Well, I have this question because I’ve heard people say using one event for multiple actions isn’t good practice and can lag your game. That’s why I asked if I should use modules.

1 Like

you can use ‘task.spawn’ in Players.PlayerAdded event in one script to run at the same time.

not recommended but just saying if you want to to that.

1 Like

I think its better to have one event handle everything than having it split across multiple scripts. This way, your able to decide which lines of code runs first.

For example: if you connect a function that sets up the player’s money and then changes it to 100, everything would run as expected.

If you decide to have one event set up the player’s money and another one which changes the money to 100, it could get messy since the event that changes the money to 100 could run before the money is even set up, leading to errors.

And of course its much more organized to have everything in one place

1 Like

Thanks for your answer! I figured it was better to do it this way, but I just wanted to double check and see what other people thought. Have a wonderful day! :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.