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

Script printing boolean values true when they are false?

I have this Local Script:

for i,v in pairs(player.PlayerGui.Quests.Background:GetChildren()) do 
if v:FindFirstChild("Active") and not v.Active then
	--Do some juicy stuff
elseif  v:FindFirstChild("Active") and v.Active then
	print("Still prints true -.-")
end
end

Active is a boolean value I have in almost every child in the folder I'm looping through.

What I want to do is for the script to "Do some juicy stuff" when that value is false (Which it is), but instead it keeps printing true even when the value is false.

I had the first value in the list checked and it was false, I ran the script and it still printed that it was true.

This is getting me so annoyed I'm already at this for 1 hour.

Any help is really appreciated!

Thanks!

1 comment

0

You need the value inside the Active ie v.Active.Value. v.Active is an instance and will be truthy.

1 answer

✓ Accepted answer

A fairly simple solution. Let me first show you through an example.

  • Insert a boolValue inside Workspace.script
  • Check in the boolValue and rename it to ValueChecker
local BooleanValue = script:FindFirstChild("ValueChecker")

if not BooleanValue then 
	print("Not")
else 
	print ("Yes")
end

Notice the output when you check and uncheck the ValueChecker

[First Time] - Yes

[Second Time] - Yes

Why?

You are not actually looking for the Value of the BooleanValue here. When you simply do if not BooleanValue then that is never true because BooleanValue does exist in the Workspace because you are simply checking whether the Value exist in the Workspace or not. If the ValueChecker was not present, then the script would print not

Since you are looking for the value of the BooleanValue, change it to if not BooleanValue.Value then

Test the code now and see the difference

local BooleanValue = script:FindFirstChild("ValueChecker")

if not BooleanValue.Value then 
	print("Not")
else 
	print ("Yes")
end

Here is a fix to your code

for i,v in pairs(player.PlayerGui.Quests.Background:GetChildren()) do 
	if v:FindFirstChild("Active") and not v.Active.Value then
    		--Do some juicy stuff
	elseif  v:FindFirstChild("Active") and v.Active.Value then
    		print("Still prints true -.-")
	end
end

Learn More

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