How to get an Enum from a string?

Hello! Currently, I am working on a game and have a small issue that I don’t know how to fix. I am basically trying to create a custom proximity prompt system and currently I am trying to match the keycode you need to press for the custom prompt to activate to the base outline of a prompt that will be inside the item. This is my code:

local userin = game:GetService("UserInputService")

local currentitem = game.Workspace.Part
local proximitypromptactive = false

userin.InputBegan:Connect(function(key)
	if currentitem ~= nil and proximitypromptactive == true then
		if key.KeyCode == Enum.KeyCode[tostring(currentitem.ProximityPrompt.KeyboardKeyCode)]
			print("triggered")
		end
	end
end)

I have no clue how to get the character E or Q or whatever into the KeyCode Enum version of it. Please help!

1 Like

currentitem.ProximityPrompt.KeyboardKeyCode is already an enum so you only have to include that.

if key.KeyCode == Enum.KeyCode[tostring(currentitem.ProximityPrompt.KeyboardKeyCode)] -- Incorrect

if key.KeyCode == currentitem.ProximityPrompt.KeyboardKeyCode -- Correct
1 Like

If you want to get the actual name of the key (ex. Q, W, E, R T), just do KeyboardKeyCode.Name.

1 Like

ig i just overthought it lol, thanks a lot!

1 Like

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