How would you create a "hold input" key?

Sorry if this is the wrong category. This is my first post…

Hello! I’m trying to create a magic move where if you hold a key, then you’ll be able to charge up a magic attack. It’s similar to Kamehameha. I want it so you have to hold the R key for 4 seconds for the magic attack to render. I tried using if statements, but that didn’t work…
If you could give me some things I should do, that would be great! Also sorry if the question sounds basic, i’m a basic scripter.
Also, I didn’t include the full script because i’m just planning it out right now.

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, typing)
     if typing then return end
     if input.KeyCode == Enum.KeyCode.R then
         if input.KeyCode == Enum.KeyCode.R then
               if input.KeyCode == Enum.KeyCode.R then 
                     if input.KeyCode == Enum.KeyCode.R then
1 Like

Your first statement is correct. Move it to #help-and-feedback:scripting-support

2 Likes

How would you move it to there?

So what you do is check if the person hit the R key four times but it resets each time because a new UIS is fired. Instead, you’d want to get the time the person hit R, and check if not released in a while loop.

Edit the post and change the category.

Alright, thanks for telling me how to change the category.

But, how would you check if the person hit the R key four times?

Would you use 4 different UIS.InputBegan events?

Also, when I try to edit the post to change where it is, I only have the following options:

Bulletin board
Development discussion
Forum Feedback

What do I do now?
Sorry for this also, this is my first post …

You’re looking for IsKeyDown. You should be able to use this to figure out if the player is holding the R key down, and count for how long.

Anyway, this is supposed to be in Scripting Support.

3 Likes

Thank you! However, when I try to change the category, it says these are my options:

Bulletin board
Development discussion
Forum Feedback

However, I found out my mistake and won’t make it again.

Hello, I know of two ways to do this, the first is using iskeydown and the second is doing a while loop inside the input conditional. I don’t recommend using iskeydown because I used it and it gave my systems some problems…