How to quickly fetch a keyCode immediately with a StringValue?

Well, I explain, when you start, you start with a default key “M”, but it does not detect it, and you have to change it with this
Place1 - Roblox Studio 28_03_2021 12_18_10 a. m. (4)

And when changing the keycode for a different one, a signal is sent to a stringValue to the clientPlace1 - Roblox Studio 28_03_2021 12_18_10 a. m. (2) Place1 - Roblox Studio 28_03_2021 12_18_10 a. m. (3)

But what I want it to do is that when starting it detects the stringValue, because it does not detect it when entering, and for it to detect it, you must change it with the GUI of the image that I put, ¿what do I do?

local Open = false
local keyText = ""
local keyText2 = ""

local MenuKey = game.Players.LocalPlayer:WaitForChild("Keys"):WaitForChild("MenuKey")
local MenuKey2 = game.Players.LocalPlayer:WaitForChild("Keys"):WaitForChild("MenuKey2")

MenuKey:GetPropertyChangedSignal("Value"):Connect(function()
	keyText = MenuKey.Value
	keyText2 = MenuKey2.Value
end)

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:connect(function(key)
	if (key.KeyCode.Name == keyText) or (key.KeyCode.Name == keyText2) then
		if Open then
			Open = false
			script.Parent.Sombras.Visible = false
		else
			Open = true
			script.Parent.Sombras.Visible = true
		end
	end
end)

Can’t you just set the default values of keyText and keyText2 to M?

local keyText = "M"
local keyText2 = "M"

HAHA sorry I didn’t think it would work

1 Like