Is your script a server script? UserInputService only works correctly in client scripts (because there can be multiple players and obviously the results of UserInputService API need to be computer-specific so there’s no sensible way to replicate them to the server, and replicating every input to the server would also cause unnecessary network traffic). For example, UserInputService:IsKeyDown() will always return false on the server.
Tool.Activated works on both client and server.
Because Tool.Activated apparently works in your script and UserInputService:IsKeyDown() doesn’t, I decided to ask this.
I think It’d be nice if Roblox gave an error when trying to access client-only APIs on the server. It could avoid confusing situations where someone either accidentally or because of a lack of understanding uses a server script when a client script is needed. However, considering Roblox’s goal to maintain backwards compatibility, it’s probably too late for them to add such errors now.