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

Can a script disable / turn on another script as well as share values?

Can a script disable / turn on another script? how?

Suppose a script, script A is turned off by another script, script B. Then script B turns script A back on. Are all previous variable values of script A, now that it is turned back on, lost? This can be quite a problem. How can one share variables between script A and script B then?

3 comments

0

Try using the .disable (at the script that you want to disable)

0

Right before Script A gets disabled you can create an Int/Object/Number/StringValue that parents to script B then when script B disables itself, you parent the values to script A, vice versa. But thats unecessary

0

Guys, thanks a lot for your answers!! Especially to Rhytic, that technique is close to what i'm looking for, not unecessary IMO unless there is a better way which i am not aware of at the moment.

1 answer

As cailir said use .disable to disable a script ex:

game:GetService("Workspace"):WaitForChild("Script").disable

One way to share variables between scripts (note: these variables only share through severscript to serverscript so if you want it to go from serverscript to localscript use a RemoteFunction)

You can use a global variable using _G.variable to set the variable do

._G.text = "string"

to retrieve the variable simple do

_G.text

Bonus:

I felt like giving you a little something extra, You learnt Global Variables and now you can learn global functions. For example instead of doing

function idk()
	wait(4)
        return "idk"
end

You can instead let that be called in any serverscript if its in a serverscript

_G.idk = function()
	wait(4)
	return(idk)
end

to call this function do

_G.idk()

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