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.
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