How to fix this bug in updating a keybind

Basically, I have a feature in my game, That changes a StringValue in a folder in replicated storage, The string holds a keybind, But in my main localscript, If I try to get the keybind, And I press the keybind in roblox, Nothing happens, Why is this?

2 Likes

can you show us stringvalue with keybind and main local script please, it will be more understandable

2 Likes

image

local key = game.ReplicatedStorage.Settings.CrouchKeybind.Value


UserInput.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end

	if Input.KeyCode == key then
            print("Hello world")
      end
end)
1 Like

You have to index the value of the string only when input pressed and not before, because it will still indexing the default value even if the value change.

local key = game.ReplicatedStorage.Settings.CrouchKeybind

UserInput.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end

	if Input.KeyCode == key.Value then
            print("Hello world")
      end
end)

Also i guess there is something missing like this, but not sure i didn’t used it for a while

if Input.KeyCode == Enum.KeyCode[key.Value] then
5 Likes

NVM! I didnt see the edit! Thanks

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.