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

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

Asked by
Ribasu 127
6 years ago
Edited 6 years ago

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?

0
Try using the .disable (at the script that you want to disable) cailir 284 — 6y
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 Rhythic 36 — 6y
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. Ribasu 127 — 6y

1 answer

Log in to vote
0
Answered by
uhTeddy 101
6 years ago

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()
Ad

Answer this question