✓ Accepted answer
Your original script, while technically correct, can be improved to make it easier to maintain. Instead of hardcoding the keys and the functions that are executed when they're pressed, you could do something like this:
local keys = {}
local function connectKey(key, onpress)
keys[key] = onpress
end
mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function(key)
for storedKey, onpress in pairs(keys) do
if storedKey == key then
onpress()
return
end
end
end
This stores a function in the keys table, indexed by the key it is linked to. To add a new keybind, just call connectKey. For example, to add a new keybind that executes on 'a', you'd use:
connectKey("a", function() print("A was pressed!") end)