Opinion on stages script using remote functions for each stage

  1. **What do you want to achieve? So I’m making a game where you spawn into a stage (place) from a gui accessed from the lobby. In the place, monsters spawn and you gotta kill them. I have stages scripts in this place that are disabled. Each of these stages scripts increase the monsters health etc so the stages get harder. When the player wins the game they have an int value that records (increased) their stage level in the players data.
    Now what I am working on is my teleport GUI to these stages- when a player presses the stage button on the gui it saves a SelectedStage int value through a remote event so that when they teleport into the place the script knows which stage script to enable. However to achieve this I need to make a remote event for each stage to record what stage the player selected in their datastore. This method is working so far however …

What I’m wondering is- can having many remote events make your game laggy even if they’re not accesses constantly? Is there a better/tidier way to achieve this?

1 Like

Remote events only take effort to handle when they are actually receiving events. Having more of them that are unused will not hurt in any significant way. It sounds however like having multiple scripts is going to cause you to have a lot of repeated code that could be simplified. Can you show an example of how you are doing this?

script that enables certain scripts to be enabled dependent on certain values that the player has.
The selectedStage.Value is what the remote events are calling to determine which script to enable.

The enabled scripts for the stages are pretty much similar except values such as the health increase…but they are all disabled until theyre enabled with the script below.
What are your thoughts?

What’s in each spawn script? Can you fix the formatting of your code block also?

my spawn scripts which will be activated when a player teleports into the place with the values of the script i posted above. However you will see that my waves stop at 3 waves while i test it…It will be stopping at 10 waves and i am wanting to add a boss in at the last wave but just making this link to my Gui player data at the moment then will have a mess about with this adding a boss and monster speed values etc…

It is not recommended to use many remote events in your game as it can potentially cause lag. A better way to achieve this would be to use a single remote event to set the SelectedStage value in the player’s data store, and pass the stage number as an argument to the remote event.

For example:

-- in the GUI button's onClick event
local stageNumber = 2 -- for example
local player = game.Players.LocalPlayer
game.ReplicatedStorage.SetSelectedStage:FireServer(player, stageNumber)

-- in the server script handling the SetSelectedStage remote event
local player = game.Players:GetPlayerByUserId(playerId)
local stageNumber = stageNumber
player.DataStore:Set("SelectedStage", stageNumber)

This way, you only have a single remote event and you can pass the selected stage number as an argument to the event. This should be more efficient and less prone to lag compared to using multiple remote events.

Thankyou. I will have a go at this and see if I can get this working.

Trhankyou so much. I’ve got this working with 1 event :partying_face:

1 Like

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