How to make an ability with pressing a key?

I want, for example, when the Z button is pressed, the player moves the mouse to a certain place and releases the button, and after the player releases the button, the ability is attacked.

I couldn’t find the answers to this question

Please help

2 Likes

The easiest and most preferred way to go about this is using Context action service, where you can bind various functions to the keys of your choice!

For further info, refer the documentation: ContextActionService (roblox.com)

2 Likes

Is it possible to sample code? I still don’t understand, that is, I understand, but still I can’t catch something in my thoughts, that is, to do it

Its a little more complicated when you want to script abilities. As the person above (@PhAnToMjose4605) said, you could use Context Action Service (Or UserInputService) to deteck Key Input.

But once you have key input detection, its all about what you want the ability to be and what functions or methods you’ll do to achieve it. I’d suggest reading more into scripting articles/watching tutorials.

https://create.roblox.com/docs/tutorials/scripting/input-and-camera/detecting-user-input
https://create.roblox.com/docs/reference/engine/classes/UserInputService

2 Likes

Note for OP:
I don’t recommend UserInputService. It works very nicely but ContextActionService allows for setting of priorities and allows to bind to multiple binds on Xbox and mobile. It makes compatibility easier.

2 Likes