How do I make a keybind for my textbutton?

So the idea here, is that I want players to be able to choose what key they want to bind to the text button, just by simply right clicking on it. (Image below)
That way, they could just right click on the text button, then any key they want on their keyboard, so that when they press the key, it will play the animation.
(The animations are multiple decal, sprite frames for the yellow character below, and not for the player’s avatar.)

I am unable to find help on that, so I am stuck on clicking text buttons to play an animation, which is rather slow and annoying.

Here’s the script.

-- player = script.Parent.Parent.Parent.Parent.Parent.Character
function One()
script.Parent.Text = "IDLE"
--CODE HERE-- (I deleted it so it's not too long, but when the deleted code is here, clicking on the text button containing this script makes the idle animation play. For the keybind thing I'm pretty sure I have to do something at the end of the script, starting at local O = true)
end

function Two()
script.Parent.Text = "IDLE"
--CODE HERE--
end




local O = true
function onClicked() 
if O == true then
	O = false
	One()

elseif O == false then
	O = true
    Two()
end
end

script.Parent.MouseButton1Down:connect(onClicked)

As one can see with the picture above, there’s a few animations there, Idle-Up-Down-Left and Right, the other words with different colors are just the character’s second form.

So what you want to do is that when a player presses a button, they can bind whatever keyboard key they want and that way play the animation?

Yeah exactly that, sorry if it’s hard to understand at first English isn’t my first language.

local choosingKey = false

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(key)
    if choosingKey then
        script.Parent.Text = tostring(key.KeyCode):gsub("Enum.KeyCode.", "")
        choosingKey = false
    end

    if tostring(key.KeyCode):gsub("Enum.KeyCode.", "") == script.Parent.Text then
        --AnimationCodeHere
    end
end)

script.Parent.MouseButton2Click:Connect(function()
    choosingKey = true
end)

MouseButton2Click, if you don’t understand means if you press it with your right mouse button, not if you click it twice, just to let you know.

Hope this helps.

Nope, I am pretty stupid when it comes to coding, what would I change to make this work? As the animations are multiple decals to make it animated, and not an actual animation that you upload in your inventory as an “animation”.

Do a wait(0.01) or wait(0.001) and change it to the next frames.