Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I tell a localscript inside of a GUI to run another when finished?

Asked by 5 years ago

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!

3 answers

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

make two scripts one in the button and one in the frame the frame one should be disable

1local DisabledS = script.Parent.Parent.DisabledScript
2DisabledS.Disabled = true
3script.Parent.MouseButton1Click:Connect(function()
4DisabledS.Disabled = false
5end)
Ad
Log in to vote
0
Answered by 5 years ago

2 local scripts

01--LOCAL SCRIPT--
02 
03 
04local button = script.Parent.TextButton --change textbutton with the butotn name
05local script2 = script.Parent.LocalScript --change localScript to the other script name
06local gui = script.Parent
07 
08button.MouseButton1Click:Connect(function()
09    script2.Disabled = false
10    gui.Enabled = false
11end)
0
Its this simple are you kidding me? Does it instantly fire the script once it is not disabled anymore? guywithapoo 81 — 5y
0
I'm pretty sure yes. Cookie_clicker2 16 — 5y
Log in to vote
0
Answered by 5 years ago

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

01local fooEnabled = false
02 
03local function foo(...)
04    if fooEnabled then
05        --stuff
06    end
07end
08 
09event1:Connect(function()
10    fooEnabled = not fooEnabled
11end)
12 
13event2:Connect(foo)

Hope this helps!

Answer this question