Well, I guess this depends sincerely on how complex you intend to make the answers.
If we’re going off of your topic title it is very simple utilizing dictionaries and checking them for an index when the time arrises:
local wordBank = {
["Hello"] = true;
["Goodbye"] = true;
}
letter.OnServerEvent:Connect(function(player,text)
if text and text ~= "" then
if wordBank[text] then
-- word found
end
end
end)
-- LOCAL SCRIPT --
local rs = game:GetService("ReplicatedStorage")
script.Parent.FocusLost:Connect(function()
rs.weDoingLetter:FireServer(script.Parent.Text)
end)
However this doesn’t seem to be the goal given the way your coding is set up.
If you want to randomly select a letter and be able to then identify that letter and the possibilities of correct entries corresponding to that letter, we need to set up more in-depth tables containing the data.
local letterBank = {
{"A","Ab","As","etc"};
{"B","Bb","Bs","etc"}; -- Continue this for the rest of the letters.
}
Now we can use this setup and implement elements from your pre-existing system.
local letterBank = {
{"A","Ab","As","etc"};
{"B","Bb","Bs","etc"};
}
local chosenLetter = math.random(1,#letterBank)
game.ReplicatedStorage.weDoingLetter.OnServerEvent:Connect(function(player,text)
if table.find(letterBank[chosenLetter],text) then
-- Passes the requirement
end
end)
-- LOCAL SCRIPT --
local rs = game:GetService("ReplicatedStorage")
script.Parent.FocusLost:Connect(function()
rs.weDoingLetter:FireServer(script.Parent.Text)
end)
I would also like to point out some general flaws in your code:
- You claim your script is in ServerStorage, meaning it will never run in the first place. If this is the case, move it into ServerScriptService so that it will run.
- You attempt to identify LocalPlayer in a server side script which does not exist, therefore your “plr” argument will always be nil. You can get the player as the first parameter passed in a
RemoteEvent.OnServerEvent
function.
- Text changed in TextBoxes do not cross the client to server boundary, you’ll need to pass the text as one of your arguments in the
RemoteEvent:FireServer
call.
Not sure how much this helps your original question as you were a bit vague in what you truthfully wanted to accomplish, but hopefully this helps you slightly.