"If" Statements

This will be a really short question.

Is it possible to do this inside an if statement? Take a look:

Before:

if instance.Name == "A" or instance.Name == "B" then

After:

if instance.Name == "A" or "B" then

Is it possible to do that? Let me know please.

This modified version is not correct and won’t work as intended. It might look like it’s checking whether instance.Name is either “A” or “B”, but it’s actually not. The reason is that "B" by itself is treated as a truthy value in most programming languages, so the if statement would always be true regardless of the value of instance.Name.

To achieve the same logic correctly, you need to keep the original format:

if instance.Name == "A" or instance.Name == "B" then

This format ensures that both comparisons are done correctly and the or operator combines their results appropriately.

2 Likes

No, because when you compare just a string, like this:

It will always return true, as the string exists.

1 Like
if instance.Name == "A" then [somthing] elseif instance.Name == "B" then [somthing] end

Nevermind, it doesn’t work. So I would have to do what I first did?

to understand fast, you’re saying if Instance.Name is a “A” then or if no instance @string “B” is a thing then.

this would be checking if Instance.Name is “B” otherwise we’re gonna run the or everytime @string “B” is a thing.

if "B" then 

whats a “B”

As others have said, the first part of the statement is checking if instance.Name is equal to A, while the second part is just checking if B, which will always just return true. If you need to check multiple names you could simply check if its name is within a table like this:

if table.find({"A","B","C"},instance.Name) then
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.