That local canhit = true
is optional variable to write, developers wrote it so they can disable some statements incase there are any bugs in future development
the if not hasKeyCard then > text.Visible = false
will’nt make the Door to tell the player that they need the Keycard to pass
But, if your question is why don’t we just write if not hasKeyCard then > text.Visible = true
, the last code is making sure that the text won’t gone visible forever when the player leave the door untouched.
Sorry for bad sentences, i hope you understand.