Cannot get a basic if statement to function

image
Literally cannot figure out what went wrong, I don’t think i can get any simpler either, help. ( it doesnt print “:(” )

These 4 lines of code aren’t even working on a script on it’s own

Please use #targeted == 0 if you’re trying to check if it’s empty.

To explain what this does:

  1. # operator counts the items in an array(do not use in dictionaries)
  2. targeted declared is an empty table
  3. #targeted equals to 0 entries in table
  4. 0 == 0 results in true
1 Like

Just curious, why not table.getn() ?

When you do targeted == {} it’s comparing the memory addresses and not deep comparing those tables to see if they contain the same elements. They’re not stored at the same address therefore your condition evaluates to false, and the print statement doesn’t run.

Interesting, maybe it’s also an option. It’s just that the table.getn() is new. Usual way to do it is with the # operator.
https://create.roblox.com/docs/reference/engine/libraries/table#getn

1 Like

what exactly are you trying to check for?

They are equivalent in luau.

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