Why does this code not work?

I have this piece of code:

local CheckOwner = mtarg.Owner
if not CheckOwner or CheckOwner.Value == player.Name then

When it runs, this error comes up.

Does putting ‘if not’ not do what I think it does, check if the thing does not exist? Or does it have something to do with ContextActionService?

Thanks for any help in advance

is that what you meant?
if not CheckOwner or not
since its checking that CheckOwner doesn’t exist it can’t assign a value for it.

1 Like

The script checks if either…

  • The CheckOwner object does not exist
  • the CheckOwner objects value is equal to the player’s name

The error is not related to the if expression. mtarg (Workspace.Bluesteel Axe) does not have a property or child named Owner

instead of local CheckOwner = mtarg.Owner
change it to local CheckOwner = mtarg:FindFirstChild(“Owner”)


Thanks… I thought I had tried that already but it worked now

1 Like
if not CheckOwner then
-- is equivalent to
if CheckOwner == nil then

The reason the or CheckOwner.Value doesn’t error is because if statements are read left to right, if the left side of or is true then it will skip the right part. not does nothing special to check existance.