Help with BindAction setup containing loops!

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I need to make a Loop that properly iterates through the code and perform that specific function for defined action.

  2. What is the issue? Include screenshots / videos if possible!
    No real issue but other than needing help trying to call functions for used inputs. I’m utilizing BindAction and to my knowledge you can pass specific functions to achieve this but the way i would like it set up is so everything needed would be in a table and searched for.


local cas = game:GetService("ContextActionService")

local KeyInput = {
	["Dashing"] = {
		actionName = "QDashInput",
	
		Function = function(plr, char, humanoid)
			local Attachment = Instance.new("Attachment")
			Attachment.Name = "VelocityAttachment"
			Attachment.Parent = char.HumanoidRootPart.CFrame
			
			local ForwardDirection = char.HumanoidRootPart.CFrame.LookVector
			local Lv = Instance.new("LinearVelocity")
			Lv.Attachment0 = Attachment
			Lv.MaxForce = 50000
			Lv.VectorVelocity = ForwardDirection * 50
			
			task.wait(0.25)
			Lv:Destroy()
			Attachment:Destroy()
		end,
		CancreateTouchButton = true,
		Keybind = {Enum.KeyCode.Q},
		
		
	},
	
	["Running"] = {
		actionName = "RunningInput",
		Function = function()
			print("I am Running")
		end,
		CancreatTouchButton = false,
		Keybind = {}
	}
}


function InputsMod.BindActions(actionName, keyInput, plr, char, humanoid)
	for _, Keyinputs in pairs(KeyInput) do
		cas:BindAction(
			KeyInput.actionName, 
			
			KeyInput.CancreateTouchButton
		)
	end
end
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried searching directly on the dev forums for a topic relating this but couldn’t find a relevant topic, I’m not sure what to try!

Your post was semi-confusing, but it seemed that you wanted to loop through a dictionary in order to bind functions to keys.

for _, v in pairs(KeyInput) do
cas:BindAction(v.Name, v.Function, v.TouchButton, table.unpack(v.Keys))
end

Each element in the dictionary should have a Name, Function, TouchButton (optional), and Keys.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.