How to use have two indexes point to the same value in a table

["Movement"] = {
		[{"LeftShift", "RightShift"}] = {Name = "Sprint", Cooldown = .5, ExtraInfo = {} },
},

So the image above depicts a table called “Movement” and its current only index is a table with {“LeftShift”, “RightShift”}

I’m wondering if it’s possible to iterate through the “Movement” table on a user’s input in order to detect both LeftShift and RightShift, so I can have both inputs pointing to the same value.

1 Like

Because tables are assigned by reference, you could make all the keys in the sprint key table point to thesame table:

local sprintValue = {Name = "Sprint", Cooldown = .5, ExtraInfo = {}}
local sprintKeys = {[Enum.KeyCode.LeftShift] = sprintValue, [Enum.KeyCode.RightShift] = sprintValue}

UIS.InputBegan:Connect(function(inp)
    if sprintKeys[inp.KeyCode] then
        -- start sprint 
    end
end)

any changes made to the sprintValue table will update for all the keys

2 Likes

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