i am trying to make a table or a string that says the keys what you need to press but i cant change the string to a Enum
This is my proccess:
local UserInputService = game:GetService("UserInputService")
local text = "abcd"
function KeyVerify(key)
local Input = UserInputService.InputBegan:Wait()
if Input.KeyCode == key then
return true
else
return false
end
end
for i = 1,#text do
repeat wait() until KeyVerify(
string.sub(text, i, i) --I need change this to a enumValue
)
print("word")
end
Not able to write code since on mobile but try using Enum.KeyCode:GetEnumItems() in a for loop to get a table of Enum items, then loop thru it and run tostring() on each of them, then compare the final letter of the Enum item to “string.sub(text,i,i)” and if they are equal, do your KeyVerify() thing
local UserInputService = game:GetService("UserInputService")
local text = "abcd"
function KeyVerify(key)
local Input = UserInputService.InputBegan:Wait()
if Input.KeyCode == key then
return true
else
return false
end
end
for i = 1,#text do
if table.find(Enum.KeyCode:GetEnumItems(), i ) then
repeat wait() until KeyVerify(
table.find(Enum.KeyCode:GetEnumItems(string.sub(text, i, i) ) )
)
print("word")
end
end
local text = 'abcd'
local iteration = 1
local CAS = game:GetService"ContextServiceAction"
--the following block is done so you can edit the text variable easily.
local t = {}
for i = 1, #text do
table.insert(t,text:sub(i))
end
local TextThingyFunction = function(Name,State)
if Name == "Type" and State == Enum.InputState.Begin then
print(t[iteration])
iteration = (iteration > #text) and 1 or iteration + 1
end
end
local function Rebind(Key)
CAS:UnbindAction("Type")
CAS:BindAction("Type", TextThingyFunction, true, Enum.KeyCode[Key])
end
Rebind("F")
Hey there again @colochosgt3!
enum.keycode includs a table and you can use brackets to reference something in it. The only thing is that you need to convert the string to uppercase to reference it, which is quite simple if you use string.upper
here is the code with these features implemented (with print to show that is working)
local UserInputService = game:GetService("UserInputService")
local text = "abcd"
function KeyVerify(key)
local Input = UserInputService.InputBegan:Wait()
if Input.KeyCode == Enum.KeyCode[string.upper(key)] then
print(key)
return true
end
end
for i = 1,#text do
repeat wait() until KeyVerify(
string.sub(text, i, i)
)
print("word")
end