Hello, I’m trying to make custom keybinds using UserInputService but there’s an issue, how do I make it where if the key pressed == a String value then a function happens? I know it works with KeyDown but I can’t seem to get it to work with UserInputService
What do you mean? I don’t quite understand what you’re asking.
im trying to do this but with UserInputService.
Plr:GetMouse().KeyDown:Connect(function(K)
if K == game.Players.LocalPlayer.PlayerScripts.KeyBinds.Crouch.KeyBind.Value then
but for some reason UserInputService doesnt allow u to use a string value as a button for some reason or i cant just get it to workl
Would this help?
https://developer.roblox.com/en-us/api-reference/class/UserInputService
I still quite don’t understand. Sorry if this is the wrong thing you were looking for.
tried this but this doesnt work
UserInputService.InputBegan:Connect(Function(Key)
If key == Keybind.Value then
and this
UserInputService.InputBegan:Connect(Function(Key)
If key.KeyCode == Keybind.Value then
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.KEY then
--run code
end
end)
will that make it where if they press the button that ='s to a value?
Are you trying to make it so that the player can set a custom keybind?
yes and if they set the KeyBind to E the Value puts the value as E and i need it where if they press the Values Value then a function happens
You’re trying to compare an Enum(input.KeyCode
) with a string, which is going to always be false. Instead compare it with Enum.KeyCode[value]
.
local value = "A"
if input.KeyCode == value then
print("doesn't work")
elseif input.KeyCode == Enum.KeyCode[value] then
print("works")
end
idk how that works. like this? or did i do it wrong
if input.KeyCode == Enum.KeyCode[game.Players.LocalPlayer.PlayerScripts.KeyBinds.Sprint.KeyBind.Value] then
Its simple
you make a folder/data with the players custom set keybind
then you would make a varible called Floor1 = player.keybind.Floor.Value
local floorkey = Enum.KeyCode[Floor1]
hope this helps