I am able to check if a person is holding down a button with UserInputService, but I want to create a button that is available on mobile. This is the function I wrote with UserInputService (Top), and this is what I could come up with for a function that I need to use for ContextActionService (Bottom).
01 | UserInputService.InputBegan:Connect( function (Input, GameStuff) |
02 | if GameStuff then return end |
03 | if Input.KeyCode = = Enum.KeyCode.LeftShift then |
06 | while UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and isPressed do |
08 | Char.Humanoid.WalkSpeed = RunningSpeed.Value |
09 | game.Workspace.CurrentCamera.FieldOfView = 72 |
12 | game.Workspace.CurrentCamera.FieldOfView = 70 |
13 | Char.Humanoid.WalkSpeed = WalkingSpeed.Value |
16 | UserInputService.InputEnded:Connect( function (Input) |
17 | if Input.KeyCode = = Enum.KeyCode.LeftShift then |
22 | function Sprinting(name, inputState, inputObject) |
23 | if inputState ~ = Enum.UserInputState.Begin then return end |
25 | while UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and isPressed do |
27 | Char.Humanoid.WalkSpeed = RunningSpeed.Value |
28 | game.Workspace.CurrentCamera.FieldOfView = 72 |
31 | game.Workspace.CurrentCamera.FieldOfView = 70 |
32 | Char.Humanoid.WalkSpeed = WalkingSpeed.Value |
35 | ContextAction:BindActionToInputTypes( "Sprint" ,Sprinting, true ) |