Hello, I am not new to scripting in Roblox Studio but there is one question that has been going on my mind for a while now. Since i wanna learn and imrpove my scripting skills, I have came here to discuss this topic. Can LocalScript disable another LocalScript?, and if it can, then how do I do that?, Do i need to set up any RemoteEvent or BindableEvent to perform such action?, Can LocalScript disable or re-enable itself? Sorry for my English, It’s not my primary language.
(first note: please move this to #help-and-feedback:scripting-support, thanks!)
A LocalScript can disable another LocalScript, indeed. You can just set the .Enabled = false
directly, like this:
script.Parent.AnotherScript.Enabled = false
A script can also disable itself, but it cannot re-enable itself. When you disable a script, it doesn’t execute.
Thank you, so you mean i can use this instead of setting bindable events everywhere because the game i am working on is quite complex and there is a lots of remote and bindable events in it. This will make my work easier for sure.
Can you describe what you want to do exactly? Why would you need bindable events?
Would also recommend to structure your events in folders. If you use networking heavily, you don’t want 100 instances cluttered around.
So for example i am trying to make a a gui and when player click the button in the gui another local script will be enabled. In this script there will be a camera shake, so when a player click button on gui the camera should shake.
For me it is kinda easier when i can just use this method instead of setting bindable event just for that one shake.
use modules for stuff like camera shake
To elaborate @Sijiti reply a bit:
When you want to reuse code → use ModuleScripts
When you want to share variables between scripts (signal on changes) → use BindableEvents
—
Bindables have to serialize/deserialize data and you’ll need to spend a lot of time setting up instances. Modules are better and have more features for reusing code (such as OOP, but that’s another topic).
Okay, but i have never worked with ModuleScript in my life. Does it run on the server or on the client? How exactly do they work?
Any recommendations on websites or Youtube channels that explain ModuleScripts?