Wow, I should really practice scripting more. I have been making a small game to practice my scripting today and ran into an issue. I wanted one script to start a different script. For example it goes down the lines of code and then reaches one that starts an entirely different script. I looked on YouTube, but didn’t quite find anything. Is this even possible? If so, how do I do it?
You can’t just enable another script with a script, but you can trigger an event instead.
So there are a few ways to do this, however, the best way is to use BindableEvent or BindableFunction, to make something happen in a different script. However, the scripts have to both be on the same side (client or server).
Correct me if I’m wrong but can’t you clone scripts from ServerStorage to ServerScriptService to start a script? If so you can just use loadstring to load code from a StringValue or whatever you want to load strings from.
edit: You also need LoadStringEnabled, a property of ServerScriptService to be enabled for it to work.
Well the most intuitive way is by changing the disabled property from true to false:
scriptPath.Disabled = false
Note: You CAN enable another script with a script just like that. I tried it 2 seconds ago. So idk why others said you can’t.
The only situation this would not work is if the scripts run on different computers (server script and client script), for this you’ll want to use a RemoteEvent.
Also be cautious about LoadStringEnabled
, you’ll likely never need this and should avoid changing the default.
You can also try using ModuleScripts, because you can require()
it from the client or the server. When you reach the bottom of one script, just require(pathToModuleScript)
and you can start a completely new script.
Instead of splitting up multiple scripts, I usually utilize declarative programming, where you utilize multiple functions to perform specific tasks to reshape something. The functions are tools that are written in place before its use. With proper elements, you can eliminate having two scripts into one single one.
To improve this, you could always use ModuleScripts
. If you don’t know what it is, consider looking it up on the forum.