Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do we do a Hold UIS function?

Asked by
Arj783 72
4 years ago

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

Log in to vote
1
Answered by 4 years ago
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)



0
Wow, thanks! I'll try that out later! Arj783 72 — 4y
0
Instead of the print ("A-Key is being held down!") insert anything you want it to do. GEILER123456 20 — 4y
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. GEILER123456 20 — 4y
0
I know lol :) Arj783 72 — 4y
View all comments (2 more)
0
I'm not too familiar with this but wound't using inputEnded be a better solution? synkrio 281 — 4y
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. GEILER123456 20 — 4y
Ad

Answer this question