I recently faced a problem where ~= does not work properly
I have a piece of code here
local function VisibleOff()
local Mains = SettingMain:GetChildren()
for _,v in pairs(Mains) do
if v.Name ~= "ChoosingFrame" or "Close" or "UICorner" then
v.Visible = false
end
end
end
It would always error
Visible is not a valid member of UICorner “Players.TwyPlasma.PlayerGui.Settings.Settings.UICorner”
So I had to resort to doing
local function VisibleOff()
local Mains = SettingMain:GetChildren()
for _,v in pairs(Mains) do
if v.Name == "ChoosingFrame" or "Close" or "UICorner" then
else
v.Visible = false
end
end
end
This problem only happened recently, so am I doing anything wrong?
local function VisibleOff()
local Mains = SettingMain:GetChildren()
for _,v in pairs(Mains) do
if v.Name ~= "ChoosingFrame" and v.Name ~= "Close" and v.Name ~= "UICorner" then
v.Visible = false
end
end
end
When you write code as if Val == "a" or "b" or "c", it’s not written to the effect of if Val is a or b or c, it’s to the effect of if Val == a is true or b is true or c is true. To fix this, you have to compare the value individually with each comparison, that being
if Val == "a" or Val == "b" or Val == "c" then
Alternatively, you could also use a dictionary to avoid this.
local Allowed = {
["ChoosingFrame"] = true,
["Clone"] = true,
["UICorner"] = true
}
...
if not Allowed[v.Name] then
v.Visible = false
end