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

BoolValue won't make the parent disabled with a loop?

Asked by
royee354 129
6 years ago

I have no idea why this line of code won't work. the following global script is inside of a Bool value that is inside of a local script.

while wait() do
if script.Parent.Value == true then
script.Parent.Parent.Disabled = true
end
end
while wait() do
if script.Parent.Value == false then
script.Parent.Parent.Disabled = false
end
end

the goal as you can see is when the parent of this script (the boolvalue) is set to true to disable the local script which is the parent of the bool value and when the value of the bool is false to undisable the local script it.

3 answers

Log in to vote
1
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

You should use Changed event instead of a while loop

script.Parent.Changed:Connect(function(val)
    script.Parent.Parent.Disabled = val
end)

As for why it doesn't work, it could be because the Disabled property doesn't "fully" disable the script. You should rather make the localscript check if the boolvalue's value is true, and if so, abort all actions it's doing, like this:

local bool = script.BoolValue

--an event example:
plr.CharacterAdded:Connect(function(char)
    if bool.Value then
        return
    end
    --normal code
end)
Ad
Log in to vote
0
Answered by
oftenz 367 Moderation Voter
6 years ago
Edited 6 years ago

Instead of doing 2 different Loops just use a conditional statement.

while wait() do
if script.Parent.Value == true then
script.Parent.Parent.Disabled = true
elseif script.Parent.Value == false then
script.Parent.Parent.Disabled = false
end

Your' second loop was never able to execute.

0
wow u beat me too it,i did the exact same thing ._. tobhyyy 26 — 6y
0
elseif without space between the 'else' and the 'if' Sir_Melio 221 — 6y
0
oops oftenz 367 — 6y
Log in to vote
-1
Answered by
tobhyyy 26
6 years ago
while wait() do
    if script.Parent.Value == true then
        script.Parent.Parent.Disabled = true
    elseif script.Parent.Value == false then 
        script.Parent.Parent.Disabled = false
    end
end

hi your welcome

Answer this question