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

Why is my boost script using Context Action Service not working?

Asked by 7 years ago
Edited 7 years ago

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
)

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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)
0
oh rip xD thanks User#15461 0 — 7y
0
oh, was about to say it doesn't work User#15461 0 — 7y
0
ok thanks User#15461 0 — 7y
0
hmm... As I said I am a beginner scripter and I don't really under stand "(string, inputstate, inputobject)". In the examples on the wiki they just put the name of the function. Please help :D User#15461 0 — 7y
Ad

Answer this question