FromValue is not a valid member of "Enum.KeyCode"

When running the code below at the very beginning of a local script placed in StarterPlayerScripts:

local keycode_values = {}

for i = 160, 254 do
	table.insert(keycode_values , Enum.KeyCode:FromValue(i))
end

There is a chance an errors pops saying “FromValue is not a valid member of “Enum.KeyCode””.

I cannot reproduce this bug myself, as I just saw the error in the logs. It happened to 20 users in a timelapse of 8 hours in my game: Survive and Kill the Killers in Area 51 !!! - Roblox

Expected behavior

According to the documentation (Enum | Documentation - Roblox Creator Hub), FromValue is a method of Enums, so there is no reason for this error to happen. I expect the function FromValue to be found and executed.

This seems like a new function. I know for a fact that both FromName and FromValue did not exist before because I and a friend needed to work-around it not existing with our own solution. Is it possible that this simply hasn’t rolled out fully yet to the client? Still problematic even if so and it should at the minimum be communicated if so, but I’m wondering if that could be the reason for it?

2 Likes

I remember implementing the use of FromValue in a testing game some months ago, so I am quite surprised if this isn’t yet rolled out on all clients now. I haven’t seen any announcement or communication, or warning about it, so I just assume it to work no matter what.

Hello homermafia1, this bug makes no sense at all and is clearly a Roblox error itself, probably caused because something related to the client’s resources may not have been loaded completely, so I suggest you use this updated version I made that will only continue the code once it is successfully completed.

local keycode_values = {}

local function GetValues()
	local Sucess, Error = pcall(function()
		for i = 160, 254 do
			table.insert(keycode_values, Enum.KeyCode:FromValue(i))
		end
	end)
	return Sucess, Error
end

while task.wait() do
	local Sucess, Error = GetValues()
	if not Sucess then
		warn(Error)
		keycode_values = {}
	else
		break
	end
end

I have and still do use this in a game and it works on the client and has for about a month now.

We’ve attempted to reproduce the issue without success. We are closing the thread for now, but please share any additional information or steps that could be valuable for us to re-open the investigation.