I am learning how to use the Context Action Service. I have a script that should print "spacewaspressed" when you press space or if you are on mobile when the button is pressed. I have a local script in starter player. Here is my script:
local contextActionService = game:GetService("ContextActionService") contextActionService:BindAction("Boost", spacepressed, true, Enum.KeyCode.Space) function spacepressed() print("spacewaspressed") end
When start the game I get "Argument 2 missing or nil" on line 3. Argument 2 is the function it is supost to fire and its spelled right so idk. Its probably something really simple that I missed but I am a beginner scripter so yeah... Thanks :D
I tried a new script that should work but it still isn't and I am getting nothing in output.
local contextActionService = game:GetService("ContextActionService") function SpacePressed() print("spacewaspressed") end contextActionService:BindAction( "Boost", SpacePressed, true, Enum.KeyCode.Space )
You need to define the function prior to binding it. Or, while you bind it.
Here's a list of parameters you should supply
local contextActionService = game:GetService("ContextActionService") contextActionService:BindAction( "Boost", function(string, inputstate, inputobject) print("waspressed") end, true, Enum.KeyCode.Space )
EDIT:
Now, this would normally work. But since Space is bound by default, you cannot overwrite it. You're going to have to use the InputBegan
function of UserInputService.
local uis = game:GetService("UserInputService"); ui.InputBegan:Connect(function(input,process) if not process then if input == Enum.KeyCode.Space then print("waspressed") end end end)