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

(Solved!) why is this conditional statement not working even though it has been returned to true?

Asked by 4 years ago
Edited 4 years ago

I've made a function where it sets the enabled property of all screen GUIs to true or false but only if the name of the screen GUI is not equal to the given string. I can't seem to get it to work, it sure did set the enabled property of all screen GUIs to what I have given but it doesn't check if the name of the screen GUI is not equal to the given string. Here's the function that I've made. It runs whenever the player pressed E

function SetGuiEnabled(bool)
    for i,v in pairs(game.Players.LocalPlayer.PlayerGui:GetChildren()) do
        if v.Name ~= "KeybindDisplays" or v.Name ~= "DialogMenu" then 
            v.Enabled = bool
        end
    end
end

the problem is at line 3 it doesn't check if the name of all screen gui is not equal to the given string. It doesn't give me any errors tho.

1 answer

Log in to vote
1
Answered by 4 years ago

The problem is with the or statement.. if "V.Name" is not equal to "KeybindDisplays" then it will immediately go down to execute v.Enabled = bool regardless of whether or not "v.Name" is equal to "DialogMenu".. the or operator just checks to see if one of it's operands are true..

so if i did true or false, it will always be true..

so use the and operator, which checks to make sure both of it's operands are true.. so true and false will return false, true and true will return true..

so here is your code:

function SetGuiEnabled(bool)
    for i,v in pairs(game.Players.LocalPlayer.PlayerGui:GetChildren()) do
        if v.Name ~= "KeybindDisplays" and v.Name ~= "DialogMenu" then 
            v.Enabled = bool
        end
    end
end
0
That explains why it sets all the ScreenGui enabled property to the given! Tysm for you're answer! DizzyGuy70 38 — 4y
Ad

Answer this question