Best way to activate stuff when the game starts

so basically im creating a system where there is a lobby, and once all players are ready/loaded in, the game should start.
and what i mean “the game should start” is that all NPC would start moving, player scripts like a health or stamina system would activate, etc.

now the problem is, what would be the best way to activate all those scripts?

now i know i could just put and if statement before any code runs, for example if gameStarted.Value == true then RUN CODE end
but that seems like a bad way of doing it/would take long to put it every script

You could store stuff in a function, and call it whenever a round begins
for e.g:

You can make a function for choosing maps ,and inside of it, put more stuff such as creating the map, teleporting the players, intermissions/timers, etc.

2 Likes

so for example, when the game starts the function could move NPC from replicatedstorage to the workspace/other server scripts ? then how should i handle player scripts like camera scripts/stamina, etc.

Yes, you could put code in the function that’ll clone the npc from replicatedstorage to workspace, and you can call it whenever you want. [If you want to use something in that function again, return that thing]

1 Like

thanks but:

what im thinking of is a GameStart function in a module script in replicated, just dont know how i should deal with the UI, local scripts and give them to player(s) on the GameStart function
(you could give a small example if you want, and im kinda tired rn so if im missing something really simple thats why)

1- Put that module in ServiceScriptService. Because exploiters could easily get stuff from replicated.

2-For the UI, you can have a string/int value , and change it on the server. On the client use Changed event for that value, and the text would be shown to each client.

1 Like

I can give you a simple example in a few minutes

1 Like

also one quick question, since the module is in server script service the client cant get it, and i would like the client to also being to get it for a “camera cutscene” function that basically displays the map. so can i move the module anywhere else? or should i create a seperate module for it?

Fire Local Scripts with events.

You can also disable scripts, and when round starts go through all the players and enable them

pretty similar cause i will have to use OnClientEvent for every single local script

You can have all of your functions in one LocalScript and check for parameters sent by the server to run the wanted function.

so your saying i should combine all of the local scripts into one main local script (thats gonna cause a local script with thousands of lines of code, is that efficient?) and Player scripts are different so they will not work compared to combining all of the StarterCharacterScripts local scripts

No, dont do that. Handle your game on the server. You can fire all clients whatever you need from there.

1 Like

This is what partially what i meant, yes. It would be good to combine the scripts into one. Then you can do something like this:

Server

.. FireClient(ftype,param1,param2,param3,etc)

Client

-- Insert Server Event Check here(ftype,param1,param2,etc)
if ftype == cutscene then
--insert code here ( use parameters for things like what cutscene has to be played etc etc)
end
-- blah blah blah more checks and functions here.

yeah but 1 script would be extremeley un-organized and not efficient

like they stated, im going to handle it on the server

Having more scripts is extremely inefficient, you can make one script in a way that it’ll be organized and properly commented.

Edit: This is because if you ever have an infinite loop in any of your scripts then this would mean that there are as many infinite loops running at the same time as there are scripts with said loops in the game.

Edit2: Also you cant do everything on the server.
Things like cutscenes or GUI must be made on the client.

1 Like

an example would help but its really late for me so im going sleep so i wont be able to reply to anyone

You could, if you have a gameStarted value, do this:

gameStarted.Changed:Connect(function(value)
    if value == true then
    --// Do stuff
    end
end)

Basically detect whenever the value changes and check if the value is set to true.

i have alot of scripts and that seems