So I have a Survive The Disasters game, and I was wondering what is the most effective way to have these disasters happen. Here are my ideas:
So this one is the most simple. I have a Script in ServerScriptService (SSS), inside which is a loop which executes functions inside this script. This is very simple, however what if I want to execute two disasters at once? I mean, its not too flexible, is it.
This one is also quite simple, I have a script, and a RemoteEvent. Everytime the RemoveEvent is called, the script executes a disaster depending on the argument which was passed through the RemoveEvent.
Alternatively, I could have a separate RemoteEvent for each disaster, but I mean, thats not effective.
This might be the best idea. So I have ModuleScripts for each disaster in ServerStorage, and a Script in SSS which Clone()s these ModuleScripts, sets their parent to SSS, and then require()s them. The ModuleScript which was called would execute the disaster, and then delete itself.
Perhaps theres a more effective way, but I don't know. I have heard of BindableEvents, but idk about those and maybe they wouldn't be effective at all.
What do you think? What's the most effective way?
The best way is to definitely use ModuleScripts
. This is how I would do it:
For each disaster, create a module that starts out like this (also put them all in a folder):
local Disaster = {} function Disaster.StartDisaster(self) -- do disaster end return Disaster
and then in the main script, do this to start the disasters
local Disasters = DisasterFolder:GetChildren() local DisasterModule = require(Disasters[math.random(1, #Disasters)]) DisasterModule:StartDisaster()
I am not the most efficient at scripting yet, but I would go with whatever you feel most comfortable with. And if you think something would work better learn more about it. Just experiment, may suck but would make the game more efficient. :D
Honestly I'm not sure but only you can figure out what works best for you, though if you want recommendations id just run it all under a script in serverscriptservice
I Would Do It Like The Free Model Version Put The Disasters In a Table And Make The Script Put Them In The Workspace Heres A Example
local disasters = {"Soldier"} local h = Instance.new("Hint",game.Workspace) while true do for i,v in pairs(disasters) do h.Text = "Chooseing Disaster" wait(3) random = math.random(1,2) disaster = game:GetService("Lighting"):FindFirstChild(v) chosen = disaster:Clone() chosen.Parent = game.Workspace h.Text = disaster.Name.." Has Been Chosen" wait(0.2) h.Text = "" for i = 25,1,-1 do h.Text = "Time Left "..i wait(1) end h.Text = "Times Up!" wait(3) game.Workspace:FindFirstChild(disaster.Name):Remove() end end
You Can Edit It If You Want