Hello, I’m trying to make a simple game almost like the game ‘Wordle.’ Any who, I’m having this problem with the background colors of the text being incorrect. They all have the same prompt. The prompt and correct word they are trying to find is the word…
EARTH
(Note, if you haven’t played Wordle, the letters that are green are in the correct position, letters that are orange are also correct but are in the wrong position, and gray letters are not in the word at all.)
PROBLEMS
1. The guessing word “FAITH” has the letters ‘A’, ‘T’, and ‘H’ shown to be correct, yet that isn’t right, the letter ‘F’ isn’t in the word we are looking for either.
It should look more like something like this:
(From a custom Wordle.)
2. The word “MOURN” has only one letter that is correct but wrong position in the guessing word. And obviously ‘M’ isn’t in the word “EARTH” but the letter ‘R’.
This guessing word should also look something like this:
Here’s the main local script code for the text updating:
The main function that should be focused on is the updateWordSets() function.
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local textBox = script.Parent.Background.MainScroll.InputWordFrame.Input
local submitEvent = ReplicatedStorage:WaitForChild("SubmitFeedback")
local function handleInput(input)
local newText = ""
for char in input:gmatch(".") do
if #newText < 5 then
if char:match("[A-Za-z]") then
newText = newText .. char:upper()
end
end
end
textBox.Text = newText
end
local function sendWordToServer(word)
if #word == 5 then
submitEvent:FireServer(word)
else
local errorSound = Instance.new("Sound", SoundService)
errorSound.SoundId = "rbxassetid://550209561"
errorSound:Play()
errorSound.Ended:Connect(function()
errorSound:Stop()
errorSound:Destroy()
end)
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(function()
handleInput(textBox.Text)
end)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Return then
local word = textBox.Text
sendWordToServer(word)
end
end)
local function updateWordSets(correctPositionLetters, incorrectPositionLetters, incorrectLetters, word)
local wordSet = script.Parent.Background.MainScroll:FindFirstChild("WordSet1")
if wordSet then
local guessLabels = wordSet:GetChildren()
local filteredLabels = {}
for _, label in ipairs(guessLabels) do
if label:IsA("TextLabel") and label.Name:find("Guess") then
table.insert(filteredLabels, label)
end
end
table.sort(filteredLabels, function(a, b)
return a.LayoutOrder < b.LayoutOrder
end)
local wordLength = #word
for i, guesslabel in ipairs(filteredLabels) do
local guessChar = word:sub(i, i)
guesslabel.Text = guessChar
if i <= correctPositionLetters then
guesslabel.BackgroundColor3 = Color3.fromRGB(150, 255, 125)
print("Correct position letter:", guessChar, "at index:", i)
elseif i <= correctPositionLetters + incorrectPositionLetters then
guesslabel.BackgroundColor3 = Color3.fromRGB(255, 175, 105)
print("Incorrect position letter:", guessChar, "at index:", i)
elseif i <= wordLength then
guesslabel.BackgroundColor3 = Color3.fromRGB(155, 155, 155)
print("Letter not in it:", guessChar, "at index:", i)
end
end
end
end
submitEvent.OnClientEvent:Connect(updateWordSets)
Server Script if that’s for any needing:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local wordList = {"EARTH"}
local submitEvent = ReplicatedStorage:FindFirstChild("SubmitFeedback")
local chosenWord = wordList[math.random(1, #wordList)]
print("Chosen word:", chosenWord)
local function checkWord(guess, target)
local correctPositionLetters = 0
local incorrectPositionLetters = 0
local incorrectLetters = 0
local correctLetters = ""
local incorrectPositionLettersLetters = ""
local incorrectLetters = ""
local targetLetters = {}
local guessLetters = {}
for i = 1, #target do
local letter = target:sub(i, i)
targetLetters[letter] = (targetLetters[letter] or 0) + 1
end
for i = 1, #guess do
local guessLetter = guess:sub(i, i)
local targetLetter = target:sub(i, i)
if guessLetter == targetLetter then
correctPositionLetters = correctPositionLetters + 1
targetLetters[guessLetter] = targetLetters[guessLetter] - 1
correctLetters = correctLetters .. guessLetter
else
guessLetters[guessLetter] = (guessLetters[guessLetter] or 0) + 1
if targetLetters[guessLetter] and targetLetters[guessLetter] > 0 then
incorrectPositionLetters = incorrectPositionLetters + 1
targetLetters[guessLetter] = targetLetters[guessLetter] - 1
incorrectPositionLettersLetters = incorrectPositionLettersLetters .. guessLetter
elseif guessLetters[guessLetter] <= (targetLetters[guessLetter] or 0) then
else
incorrectLetters = incorrectLetters .. guessLetter
end
end
end
return correctPositionLetters, incorrectPositionLetters, incorrectLetters, correctLetters, incorrectPositionLettersLetters
end
local function handleWordSubmission(player, word)
local correctPositionLetters, incorrectPositionLetters, incorrectLetters = checkWord(word, chosenWord)
print("Correct position letters:", correctPositionLetters)
print("Incorrect position letters:", incorrectPositionLetters)
print("Incorrect letters:", incorrectLetters)
submitEvent:FireClient(player, correctPositionLetters, incorrectPositionLetters, incorrectLetters, word)
end
submitEvent.OnServerEvent:Connect(handleWordSubmission)