Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

local DisabledS = script.Parent.Parent.DisabledScript
DisabledS.Disabled = true
script.Parent.MouseButton1Click:Connect(function()
DisabledS.Disabled = false
end)

2 local scripts

--LOCAL SCRIPT--


local button = script.Parent.TextButton --change textbutton with the butotn name
local script2 = script.Parent.LocalScript --change localScript to the other script name
local gui = script.Parent

button.MouseButton1Click:Connect(function()
	script2.Disabled = false
	gui.Enabled = false
end)

2 comments

0

Its this simple are you kidding me? Does it instantly fire the script once it is not disabled anymore?

0

I'm pretty sure yes.

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

local fooEnabled = false

local function foo(...)
	if fooEnabled then
		--stuff
	end
end

event1:Connect(function()
	fooEnabled = not fooEnabled
end)

event2:Connect(foo)

Hope this helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.