I’m trying to make a wordle game in Roblox Studio, but the system doesn’t know when to put a letter as green (in the right place of the word you’re guessing), but It can easily put the letter in yellow (not in right place of guessing letter, but letter is in the word).
As you can see in this image, the word is KEYS. This means the K in the image is supposed to be green, but is yellow. (the yellow, and black letters are correct)
SCRIPT:
local btn = script.Parent
local A1 = script.Parent.Parent.Parent.Words.A1
local A2 = script.Parent.Parent.Parent.Words.A2
local A3 = script.Parent.Parent.Parent.Words.A3
local A4 = script.Parent.Parent.Parent.Words.A4
local HWTxt = script.Parent.Parent.Parent.Parent.HIDDENwordTXT
local combinedGuess = tostring(A1.Text..A2.Text..A3.Text..A4.Text)
btn.MouseButton1Click:Connect(function()
print(combinedGuess)
if A1.Text ~= "" and A2.Text ~= "" and A3.Text ~= "" and A4.Text ~= "" then
for i = 1,4 do
local target = nil
wait(0)
if i == 1 then target = A1
elseif i == 2 then target = A2
elseif i == 3 then target = A3
elseif i == 4 then target = A4
end
wait(0)
if string.find(tostring(HWTxt.Text),tostring(target.Text)) then
target.TextColor3 = Color3.fromRGB(255, 255, 0)
--to make the guessing letter yellow
wait(0)
--here's where the green check starts!
if tostring(HWTxt.Text):sub(i) == tostring(target.Text) then
target.TextColor3 = Color3.fromRGB(0, 255, 0)
--to make the guessing letter green
else
print(tostring(HWTxt.Text):sub(i),tostring(target.Text),i)
--output >>
--KEYS K 1
--EYS Y 2
--YS E 3
--[CORRECT WORD]'s char in order of what # **i** is TO [CHAR THAT PLR TYPED]
end
end
end
end
end)
Please help!