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

How would I disable an object using a bool-value?

Asked by 10 years ago

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.

3 answers

Log in to vote
2
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

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:

1script.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
7end)

You can make your own boolean values in your script like this (using LocalScript's property itself):

01IsTrue = false
02 
03script.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
11end)

Working script while using a BoolValue:

01script.Parent.IsTrue.Value = false
02 
03script.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
09end)
10 
11script.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
17end)

Schematic

1Part (Object) >     ClickDetector (Object)
2 
3                    IsTrue (Value Object)
4 
5                    Script (Object; where the aforementioned code is at)
6 
7                    LocalScript (Object)
0
Aw, a downvote. :( Why? Redbullusa 1580 — 10y
0
Overcomplicated, honestly. This question has a simple answer, no need to draw it out so much. adark 5487 — 10y
0
Ah, woops. xD Thanks for the advice. Redbullusa 1580 — 10y
0
Adark, it doesn't kill to explain everything. Some people want a thorough answer, others want a short and sweet one. M39a9am3R 3210 — 10y
0
Great answer though, dude. You gave a very thorough explanation that would help anyone who's new to BoolValues. Upvote! bobafett3544 198 — 10y
Ad
Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

I don't know what you script is doing, but the basis of it works like this:

1local boolValue = script.Parent.Enab --This is the BoolValue, obviously
2 
3function someFunction()
4    if not Enab.Value then return end
5    --code, will not run if 'Enab's Value is set to `false`
6end

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:

1local boolValue = script.Parent.Enab
2 
3if Enab.Value then
4    --code, will not ruin is 'Enab's Value is set to `false`
5end
Log in to vote
-2
Answered by 10 years ago

I think you can do this but i'm not sure:

1local disablevalue = game.Workspace.disablevalue -- the name of the boolvalue
2if disablevalue.Value == true then
3script.Parent.Disabled = true -- the localscript is the script's parent
4else then
5script.Parent.Disabled = false
6end

I think it will work, but i'm not certain.

Answer this question