Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do we do a Hold UIS function?

As you can see in the title, my question is simple. For UserInputService, how do make a hold input? As pro developers must have seen, UIS is really chunky. You have to keep pressing that button rapidly and repeatedly. How do we make a hold input? Like in a normal roblox character, you HOLD "W" to move. How is that? Is there a way to write it in code?

1 answer

✓ Accepted answer
local UserInputService = game:GetService("UserInputService")
local aKeyPressed = false

UserInputService.InputBegan:Connect(function(input,GameProcessedEvent)
 if input.KeyCode == Enum.KeyCode.A then
  aKeyPressed = true

while aKeyPressed == true do
  wait()
print ("A-Key is being held down!")

end
end
end)

UserInputService.InputEnded:Connect(function(input,GameProcessedEvent)
 if input.KeyCode == Enum.KeyCode.A then
aKeyPressed = false
end
end)



6 comments

0

Wow, thanks! I'll try that out later!

0

Instead of the print ("A-Key is being held down!") insert anything you want it to do.

0

And at line 5, just change the last letter to whatever you want. I did it with A but you can just remove this A and put Z in there, for example and this event will happen, when you press Z.

0

I know lol :)

0

I'm not too familiar with this but wound't using inputEnded be a better solution?

0

@synkrio what do you mean? I did use InputEnded, line 16. I'm not too familiar with this too, I just know that this works.

This discussion is preserved as it was. New answers, comments, and votes are closed.