I was recently creating a custom keybind system for my game, and i have struggled a bit with detecting if a UIS input is one of the keybinds.
here’s essencially what im doing:
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Char = Player.Character
local BindFolder:Folder = Char.KeybindContainer
local BindTable = {
BindFolder:WaitForChild("BindOne")
--etc, through five binds
--the "binds" are string values inside a folder. this feels rather inefficient to me, there honestly has to be a better way to do this. whatever.
}
function Connection(Input, GPE)
if GPE then return end
if BindTable[Input.Keycode] then
--remote connection
end
--how would i detect that?!?
--for reference, i also have a module that saves and loads DataStores for keybinds.
--however, i dont want to save a datastore everytime they update their keybinds, that would be terrible honestly.
--i also tried Attributes but i didn't know what i should parent them to.
--also, i dont just need to know if it was one of the keybinds, i need to know WHAT keybind it was, so i can fire the appropriate RemoteEvent.
are u trying to detect what the keycode was pressed that triggers that function?
local UIS = game:GetService("UserInputService")
local BindTable = {
"F",
"M",
}
UIS.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if BindTable[input.KeyCode.Name] then
end
end)
all enums have .Name property that returns the string of the last word in it
they have to be custom keybinds. the player can change them remotely, so it cannot have the values stored in a script. this would work for a non-custom keybind system, though.
that’s what i tried to do, but values seems inefficient and i would need to have to determine which of five remote events to fire, which does not seem optimized.
Plus, if the user wants one of the binds to be a number, the enum name would be One instead of 1. having at least ten separate specifications for keys would be janky at absolute best, probably very laggy too.
even so, this is off topic. please remain on topic and soften your tone. if i were to use one remote, how would the script receiving the remote know what ability to use? all that would be passed is, for example:
"G"
if the player sets custom keybinds, how would the receiving script know what “G” is if its not linked to anything? hence the reason i was using five separate remote events to fire individually, according to input.
not everyone has the experience you do. please be respectful.
local Keybinds = {}
local ListeningToKeybind = false
local WhatAction = nil
UIS.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if ListeningToKeybind == true and WhatAction ~= nil then
Keybinds[input.KeyCode.Name] = WhatAction
ListeningToKeybind = false
WhatAction = false
else
if Keybinds[input.KeyCode.Name] ~= nil then
print("The Action With This Keybind is = "..Keybinds[input.KeyCode.Name])
end
end
end)
local function SetNewKeybind(Action)
ListeningToKeybind = true
WhatAction = Action
end
SetNewKeybind("Heavy Attack")
--Im Pretty sure u guys knows how to DataStore table like Keybinds