#Avoid content log error when interacting with empty hand

1 messages · Page 1 of 1 (latest)

tame current
#

So I have this code that uses the PlayerInteractWithEntityAfterEvent but when a player interacts with an entity while having an empty hand it'll be read as undefined itemStack and throws an error. Is there a way to overcome this?

Content log error:
[Scripting][error]-TypeError: cannot read property 'typeId' of undefined at <anonymous> (entry.js:169)

fast escarp
#

You can do if (!item) return; which will immediately stop the code if item is undefined

flint tartan
#

you could just put a question mark before .typeId as another option
like: item?.typeId

junior viper