Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

1 comment

0

read my answers comments

1 answer

✓ Accepted answer
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)) 

3 comments

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.

0

give me robux

0

only accepting 500+

This discussion is preserved as it was. New answers, comments, and votes are closed.