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:

script.Parent.BoolValue.Changed:connect(function ()
    if script.Parent.BoolValue == true then
        script.Parent.LocalScript.Disabled = true
    else
        script.parent.LocalScript.Disabled = false
    end
end)

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

IsTrue = false

script.Parent.ClickDetector.MouseClick:connect(function ()
    if IsTrue == false then
        IsTrue = true
        script.Parent.LocalScript.Disabled = true
    else
        IsTrue = false
        script.Parent.LocalScript.Disabled = false
    end
end)

Working script while using a BoolValue:

script.Parent.IsTrue.Value = false

script.Parent.ClickDetector.MouseClick:connect(function ()
    if script.Parent.IsTrue.Value == false then
        script.Parent.IsTrue.Value = true
    else
        script.Parent.IsTrue.Value = false
    end
end)

script.Parent.IsTrue.Changed:connect(function ()
    if script.Parent.IsTrue.Value == false then
        script.Parent.LocalScript.Disabled = false
    else
        script.Parent.LocalScript.Disabled = true
    end
end)

Schematic


Part (Object) > ClickDetector (Object) IsTrue (Value Object) Script (Object; where the aforementioned code is at) 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:

local boolValue = script.Parent.Enab --This is the BoolValue, obviously

function someFunction()
    if not Enab.Value then return end
    --code, will not run if 'Enab's Value is set to `false`
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:

local boolValue = script.Parent.Enab

if Enab.Value then
    --code, will not ruin is 'Enab's Value is set to `false`
end
Log in to vote
-2
Answered by 10 years ago

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

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

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

Answer this question