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).
UserInputService.InputBegan:Connect(function(Input, GameStuff)
if GameStuff then return end
if Input.KeyCode == Enum.KeyCode.LeftShift then
isPressed = true
LoadRunAnim:Play()
while UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and isPressed do
wait()
Char.Humanoid.WalkSpeed = RunningSpeed.Value
game.Workspace.CurrentCamera.FieldOfView = 72
end
isPressed = false
game.Workspace.CurrentCamera.FieldOfView = 70
Char.Humanoid.WalkSpeed = WalkingSpeed.Value
end
end)
UserInputService.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift then
isPressed = false
end
end)
function Sprinting(name, inputState, inputObject)
if inputState ~= Enum.UserInputState.Begin then return end
LoadRunAnim:Play()
while UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and isPressed do
wait()
Char.Humanoid.WalkSpeed = RunningSpeed.Value
game.Workspace.CurrentCamera.FieldOfView = 72
end
isPressed = false
game.Workspace.CurrentCamera.FieldOfView = 70
Char.Humanoid.WalkSpeed = WalkingSpeed.Value
end
ContextAction:BindActionToInputTypes("Sprint",Sprinting,true)
