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

How do you get BindAction (ContextActionService) to play once?

Asked by
0te 35
4 years ago

Hello,

Whenever I use BindAction to a function, the function plays and doesn't stop.

Here is the code I am using:

local function toolActivated(actionName, inputState, inputObject)
        currentModule = require(script[inputObject.KeyCode.Name])

        currentModule.Weld(currentFoot)
        currentModule.TouchedEvent(currentFoot)
    end
    CAS:BindAction('Fire', toolActivated, false, mousebutton1, 'q', 'e', 'r', 't', 'y', 'f', 'g', 'h', 'z', 'x', 'c', 'v', 'b', 'n') 

When I press one of the buttons that triggers the function, the "TouchedEvent" will play continuously. The touched event is basically a touched function.

(____.Parent.Touched:connect(function()) etc.)

However, the goal is that I only want to play the touched function ONCE when the bindaction is triggered.

I've tried to think about booleans and a way to unbind the action but I just cannot get my head around it.

I'm curious to find out methods to solving this that any of you may have and I appreciate any help.

0
read my answers comments iuclds 720 — 4y

1 answer

Log in to vote
1
Answered by
iuclds 720 Moderation Voter
4 years ago
Edited 4 years ago
local function toolActivated(actionName, inputState, inputObject)
    if inputState ~= Enum.UserInputState.Begin then
        return
    end

    currentModule = require(script[inputObject.KeyCode.Name])
    currentModule.Weld(currentFoot)
    currentModule.TouchedEvent(currentFoot)
end

local Inputs = {Enum.KeyCode.Q,Enum.KeyCode.E,Enum.KeyCode.R,Enum.KeyCode.T,Enum.KeyCode.Y,Enum.KeyCode.F,Enum.KeyCode.G,Enum.KeyCode.H,Enum.KeyCode.Z,Enum.KeyCode.X,Enum.KeyCode.C,Enum.KeyCode.V,Enum.KeyCode.B,Enum.KeyCode.N, Enum.UserInputType.MouseButton1}

CAS:BindAction('Fire', toolActivated, false, unpack(Inputs)) 
0
Thank you for the help and I've always wanted to find a way to put a table in to the bindaction. Didn't know unpack was a thing, thanks mate. 0te 35 — 4y
0
give me robux iuclds 720 — 4y
0
only accepting 500+ iuclds 720 — 4y
Ad

Answer this question