In my last question, which BlueTaslem answered it, I wanted to disable a Local-Script. He said I should use a bool-value. That's my question. I want to disable a Local-Script, that's the only choice I have, if I change it's parent, it's gonna bug out.
A boolean value is basically the check-box you see in properties, with the indicator "check" mark yields true (and the absence of a "check" mark yields false). In a LocalScript, there are two boolean values:
Archivable Value (false = LocalScript won't be copied/cloned, and access to it is going to return nil)
Disabled Value (false = LocalScript will execute its code)
In your case, set the boolean value for the "Disabled" property as "true" (check mark it).
Ta-da! Your LocalScript is now disabled.
But if you want to use a BoolValue (which, in my opinion, is useless since there's one already in the object), you'll have to do something along the lines of this:
1 | script.Parent.BoolValue.Changed:connect( function () |
2 | if script.Parent.BoolValue = = true then |
3 | script.Parent.LocalScript.Disabled = true |
4 | else |
5 | script.parent.LocalScript.Disabled = false |
6 | end |
7 | end ) |
You can make your own boolean values in your script like this (using LocalScript's property itself):
01 | IsTrue = false |
02 |
03 | script.Parent.ClickDetector.MouseClick:connect( function () |
04 | if IsTrue = = false then |
05 | IsTrue = true |
06 | script.Parent.LocalScript.Disabled = true |
07 | else |
08 | IsTrue = false |
09 | script.Parent.LocalScript.Disabled = false |
10 | end |
11 | end ) |
Working script while using a BoolValue:
01 | script.Parent.IsTrue.Value = false |
02 |
03 | script.Parent.ClickDetector.MouseClick:connect( function () |
04 | if script.Parent.IsTrue.Value = = false then |
05 | script.Parent.IsTrue.Value = true |
06 | else |
07 | script.Parent.IsTrue.Value = false |
08 | end |
09 | end ) |
10 |
11 | script.Parent.IsTrue.Changed:connect( function () |
12 | if script.Parent.IsTrue.Value = = false then |
13 | script.Parent.LocalScript.Disabled = false |
14 | else |
15 | script.Parent.LocalScript.Disabled = true |
16 | end |
17 | end ) |
Schematic
1 | Part (Object) > ClickDetector (Object) |
2 |
3 | IsTrue (Value Object) |
4 |
5 | Script (Object; where the aforementioned code is at) |
6 |
7 | LocalScript (Object) |
I don't know what you script is doing, but the basis of it works like this:
1 | local boolValue = script.Parent.Enab --This is the BoolValue, obviously |
2 |
3 | function someFunction() |
4 | if not Enab.Value then return end |
5 | --code, will not run if 'Enab's Value is set to `false` |
6 | end |
Alternatively, if you're not using a function, you can remove that not
and put the code you want to disable inside of the if
statement:
1 | local boolValue = script.Parent.Enab |
2 |
3 | if Enab.Value then |
4 | --code, will not ruin is 'Enab's Value is set to `false` |
5 | end |
I think you can do this but i'm not sure:
1 | local disablevalue = game.Workspace.disablevalue -- the name of the boolvalue |
2 | if disablevalue.Value = = true then |
3 | script.Parent.Disabled = true -- the localscript is the script's parent |
4 | else then |
5 | script.Parent.Disabled = false |
6 | end |
I think it will work, but i'm not certain.