Home > Blockchain >  Lua UI Text == multiple string's with or's
Lua UI Text == multiple string's with or's

Time:12-13

Now im really new to lua and need a little help with this This script checks some text on the player UI, and It works if It equals one thing for example : game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "UNIVERSELORD" But does not work if I add the or game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "UNIVERSELORD" or "TANKTOP" It ends up doing it no matter what, and im not sure why, it works if I only put one name though, I would appreciate help thanks!

CodePudding user response:

You already had the same question closed just few days ago due to the lack of details. It's not clear WHY you'd want to add "or" to a text, so you need to explain clearly and provide an example with some context where this usage would make some sense.

In terms of the "or" statement, it doesn't produce the result you want because it returns the first result that is evaluated as non-false, so when you have 1 or 2 expression, the result is 1, as it's evaluated left-to-right and this is a non-false results. Similarly in your case, the expression "UNIVERSELORD" or "TANKTOP" is evaluated to "UNIVERSELORD", as it's the first non-false value that is encountered.

Unfortunately nobody can tell you what to change it to, as there is not enough details in the question about your goal. Possibly an XY Problem.

[updated] Based on your comment, you need to split the or into two complete comparisons: game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "UNIVERSELORD" or game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "TANKTOP"

  • Related