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

[SOLVED] Why is UserInputState not working? No errors in the output.

Asked by
8_zn 21
5 years ago
Edited 5 years ago

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\\--
02local contextActionService = game:GetService("ContextActionService")
03 
04--//Camera\\--
05local currentCamera = workspace.CurrentCamera
06 
07--//Other\\--
08local character = script.Parent
09local humanoid = character:WaitForChild("Humanoid")
10local statsFolder = character:WaitForChild("Stats")
11local statsDinosaur = statsFolder.Dinosaur
12local statsActions = statsFolder.Actions
13 
14--//Script\\--
15local function mobileSprint(inputState)
View all 30 lines...
0
I've never used ContextActionService, but maybe the error is the fourth argument of: local mobileSprintButton = contextActionService:BindAction("MobileSprintButton", mobileSprint, true, Enum.KeyCode.LeftShift) GenuineWaffles 35 — 5y
0
It has to do something with the UserInputState because before the "if statsActions.CanSprint.Value then" I added a print("test") and it printed "test" in the output. 8_zn 21 — 5y
0
Add a print(inputState) before the "if statsActions.CanSprint.Value then" and see what happens BrockRocksYourSocks 48 — 5y
0
Sorry for the 5hr late response, but in the output, it prints "MobileSprintButton." 8_zn 21 — 5y

2 answers

Log in to vote
1
Answered by
8_zn 21
5 years ago

I fixed the problem myself. Here is the final script:

01--//Services\\--
02local contextActionService = game:GetService("ContextActionService")
03 
04--//Camera\\--
05local currentCamera = workspace.CurrentCamera
06 
07--//Other\\--
08local character = script.Parent
09local humanoid = character:WaitForChild("Humanoid")
10local statsFolder = character:WaitForChild("Stats")
11local statsDinosaur = statsFolder.Dinosaur
12local statsActions = statsFolder.Actions
13 
14--//Script\\--
15local function Sprint(bindName, inputState)
View all 25 lines...
Ad
Log in to vote
0
Answered by 5 years ago

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.

0
I have no idea why this answer is accepted, but I will give this a try and if it works, then I'll leave this answer accepted. 8_zn 21 — 5y
0
It doesn't seem to work, I might have did it wrong? The parameters I have are (bindName, inputObject, inputState). 8_zn 21 — 5y

Answer this question