Alright, so this might sound kind of stupid but I’m trying to make a Keybind Script. The Script is parented to a Button inside of a frame. So when i run this script it checks for a left click on the button, then gets the key that was pressed on the keyboard, and saves it to a variable. This works fine however I have 4 of these (for 4 keybinds) and when i click on the next buttons the key for the previous button updates to the button i just pressed?! I literally do not even know how that makes sense because the button click should end. Any help will be appreciated thanks! 
In the end, I want all 4 buttons to save individual keybinds, and not just one for all 4 buttons!
Here are a few screenshots followed by the code itself:
Note: Please keep in mind that I’m not a GUI designer!
→ This is what it should look like
→ The first key changes, like it should

→ After the first keybind changing you can see how all buttons are showing the same key
If you change just 1 key out the previous ones you already custom assigned a keybind THEY WILL ALL CHANGE TO THE ONE YOU JUST PRESSED!
Code for the first button: (they are all the same just the numbers are different, eg key1, key2 etc)
local UserSettings = require(game.ReplicatedStorage.UserSettings)
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Text = "Press Any Key"
mouse.KeyDown:connect(function(key1)
UserSettings.Key1 = key1
script.Parent.Text = "Key 1: "..key1
end)
end)
UserSettings is just a module script. It is where it stores the keybinds that were pressed.
I have tried going on the web, trying to fix it myself, using debounces, using mouseup and a lot of other things. (can’t really remember)
again, any help will be appreciated thanks!!
- MasterWindowz7And10


