I have a button GUI hooked up to a localscript, and when its clicked I want it to tell another local script inside of the player to "turn on" I guess. Whats the best way to do this?
I was thinking of putting a value inside of the player and when its changed, it will fire the other localscript.
I also thought of putting a remote event inside of the player, but I have no idea if that will even work so I haven't tried it.
Thanks!
make two scripts one in the button and one in the frame the frame one should be disable
1 | local DisabledS = script.Parent.Parent.DisabledScript |
2 | DisabledS.Disabled = true |
3 | script.Parent.MouseButton 1 Click:Connect( function () |
4 | DisabledS.Disabled = false |
5 | end ) |
2 local scripts
01 | --LOCAL SCRIPT-- |
02 |
03 |
04 | local button = script.Parent.TextButton --change textbutton with the butotn name |
05 | local script 2 = script.Parent.LocalScript --change localScript to the other script name |
06 | local gui = script.Parent |
07 |
08 | button.MouseButton 1 Click:Connect( function () |
09 | script 2. Disabled = false |
10 | gui.Enabled = false |
11 | end ) |
You should always avoid disabling scripts whenever possible. If you always use disabling scripts as a method to disable certain features, you'll split code that makes sense to all be in the same script into different scripts, which causes problems when you need to sync each feature and when you share values. Also, more scripts typically means more threads, which if you split enough scripts up, this may build up and become an issue.
To replace the need to disable different scripts, you can use a variable to tell something if it should be enabled or not. For example, you can have some code like
01 | local fooEnabled = false |
02 |
03 | local function foo(...) |
04 | if fooEnabled then |
05 | --stuff |
06 | end |
07 | end |
08 |
09 | event 1 :Connect( function () |
10 | fooEnabled = not fooEnabled |
11 | end ) |
12 |
13 | event 2 :Connect(foo) |
Hope this helps!