Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

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.

3 comments

0

wow u beat me too it,i did the exact same thing ._.

0

elseif without space between the 'else' and the 'if'

0

oops

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

This discussion is preserved as it was. New answers, comments, and votes are closed.