lets say the player has to input an answer to the question “name a famous soccer player”. In the module that stores the data, the answer to said questions are. “Ronaldo”, “Messi”, “Suarez”. But the player inputs “Cristiano Ronaldo” instead of just his last name. How could I detect it and shorten it to the closest answer
4 Likes
To create an autocorrect system on Roblox, you can utilize the TextService module to check and correct the input text. Here’s an example of how you can implement it: 1. Create a LocalScript inside a TextButton or TextBox object. 2. Add the following code to the LocalScript:
lua
local TextService = game:GetService("TextService")
local inputTextBox = script.Parent -- Replace "script.Parent" with the reference to your TextBox or TextButton
-- Function to autocorrect the text
local function autocorrectText(inputText)
-- Use the TextService module to autocorrect the input text
local autocorrectedText = TextService:FilterStringAsync(inputText, inputTextBox.UserId):GetChatForUserAsync(inputTextBox.UserId)
-- Set the corrected text back to the TextBox or TextButton
inputTextBox.Text = autocorrectedText
end
-- Connect the autocorrect function to the TextBox or TextButton's FocusLost event
inputTextBox.FocusLost:Connect(function()
autocorrectText(inputTextBox.Text)
end)
- Save the LocalScript and test it in-game. Now, whenever the user finishes typing in the TextBox or TextButton and loses focus (e.g., by clicking outside the input field), the autocorrectText function will be called. It will use the TextService module to autocorrect the input text based on Roblox’s chat filter settings and set the corrected text back to the TextBox or TextButton. Please note that the autocorrection will be based on Roblox’s chat filter settings, so it may not catch all possible typos or misspellings. Additionally, the TextService module may not be perfect in all cases and may not always provide the desired results. You may need to further customize or refine the autocorrection logic based on your specific requirements.
1 Like
yeah I can use string.find to get a word inside of a string but what if the the answer is “John smith” but the player only types “John” and I want it to autocorrect to the longer form. how would I do that
In order to make an auto correct system you can use filter string a sync
You need to use the filter string I think
function Input(Answer, Data)
if typeof(Data) == 'table' then
local DeltaTimes = 0
local Letters = {}
repeat
for i = 1, #Data[DeltaTimes] do
Letters[i] = string.sub(Data[DeltaTimes], i, i)
end
local __C = ''
for i = 1, #Letters do
if string.sub(__C, i,i) == Answer[i] then
__C = __C .. string.sub(__C, i,i)
end
end
if string.len(__C) > string.len(tostring(Data[DeltaTimes])) / 2 + 2 then
return true, 'Correct'
elseif string.len(__C) > string.len(tostring(Data[DeltaTimes])) * 2 - 2 then
return true, 'Correct'
else
return false, 'Incorrect'
end
until DeltaTimes == table.maxn(Data)
end
return false, 'Unknown Stereocase'
end