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

Script printing boolean values true when they are false?

Asked by 6 years ago
Edited 6 years ago

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!

0
You need the value inside the Active ie v.Active.Value. v.Active is an instance and will be truthy. User#5423 17 — 6y

1 answer

Log in to vote
4
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
6 years ago
Edited 6 years ago

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

Ad

Answer this question