When I am holding down the ContextActionService button using the emulator, it does not work. This script is a local script located inside the character.
01 | --//Services\\-- |
02 | local contextActionService = game:GetService( "ContextActionService" ) |
03 |
04 | --//Camera\\-- |
05 | local currentCamera = workspace.CurrentCamera |
06 |
07 | --//Other\\-- |
08 | local character = script.Parent |
09 | local humanoid = character:WaitForChild( "Humanoid" ) |
10 | local statsFolder = character:WaitForChild( "Stats" ) |
11 | local statsDinosaur = statsFolder.Dinosaur |
12 | local statsActions = statsFolder.Actions |
13 |
14 | --//Script\\-- |
15 | local function mobileSprint(inputState) |
I fixed the problem myself. Here is the final script:
01 | --//Services\\-- |
02 | local contextActionService = game:GetService( "ContextActionService" ) |
03 |
04 | --//Camera\\-- |
05 | local currentCamera = workspace.CurrentCamera |
06 |
07 | --//Other\\-- |
08 | local character = script.Parent |
09 | local humanoid = character:WaitForChild( "Humanoid" ) |
10 | local statsFolder = character:WaitForChild( "Stats" ) |
11 | local statsDinosaur = statsFolder.Dinosaur |
12 | local statsActions = statsFolder.Actions |
13 |
14 | --//Script\\-- |
15 | local function Sprint(bindName, inputState) |
It looks like the sprint function is missing some parameters. Functions bound via BindAction
are called with three parameters -- the name given by BindAction
, the UserInputState
, and an InputObject
.
If a function is called with more parameters than it actually has, the excess ones will be ignored. In this case, since the sprint function only has one parameter, it gets the name, but not the UserInputState
value or the InputObject
.