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 exampleif 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.
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]
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.
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?
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
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.
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.