I’m using ContextActionService to create my actions, but I don’t know how to efficiently ‘unpack’ all of them from my list. I’ve tried using unpack() but It only works for the first value in the list.
ContextActionService:BindAction("Sprint", onSprintInput, true, ...)
the last argument is vararg, normally, you can fit in unpack(keyboardMouseBinds["Sprint"]) and it will take all of the values. however, it only works if the unpacked values is used as the final vararg argument.
since you wrote unpack(keyboardMouseBinds["Sprint"]), unpack(gamepadBinds["Sprint"]), the first unpacked list is not the ‘final’ argument anymore, so it cut short to 1 value. and then the next unpacked list don’t get processed because the vararg think it got that 1 value already.
so overall it is just 1 value being passed in.
we have to go the long way to combine two arrays into one first
local t1 = keyboardMouseBinds["Sprint"]
local t2 = gamepadBinds["Sprint"]
local t3 = {}
for i, v in pairs(t1) do
table.insert(t3, v)
end
for i, v in pairs(t2) do
table.insert(t3, v)
end
ContextActionService:BindAction("Sprint", onSprintInput, true, unpack(t3))