Simple Decode Script Doesnt Work

Basically, as the title says, my decode script doesn’t work. I tried substituting finaltext with “” at the start and replacing “” in the gmatch with “.” but it didn’t work. Here’s my current code:

local decoder = require(game.ReplicatedStorage.ClientDecoder)
local textbox = script.Parent.TextBox
local textbutton = script.Parent.TextButton
local textlabel = script.Parent.TextLabel
textbutton.MouseButton1Click:Connect(function()
	print("CLICKED")
	local finaltext
	local text = textbox.Text
	local letter = string.gmatch(text, "")
	for j = 1, 26 do
		local key = decoder.KeyboardUp[j]
		local uppercase = decoder.UpperKeywords[j]
		local lowercase = decoder.LowerKeywords[j]
		for i in letter do
			if i == key then
				finaltext = finaltext..uppercase
				textlabel.Text = finaltext
				if finaltext == nil then
					finaltext = uppercase
				else
					finaltext = finaltext .. uppercase
				end
			end
		end
	end
end)

(Note: finaltext still appears as nil at the end)
Thanks for helping!

Mind posting what the decoder does? Because it seems quite hard to see whats wrong if your decoder doesn’t show whats going on.

It currently does nothing. What it’s supposed to do is decode a code in the pattern (Q = A, W = B, E = C… So QWERTY should be ABCDEF) No error in output as well.

1 Like

Any console errors? Could we see the script of the required module?

Absolutely no errors, neither console nor output shows them. Anyways here’s the current module script:

local clientsidedecoder = {}
clientsidedecoder.UpperKeywords = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
clientsidedecoder.LowerKeywords = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
clientsidedecoder.KeyboardUp = {"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M"}
return clientsidedecoder

Is the UI a Surface GUI parented to a part or Screen GUI parented to the StarterGUI folder?

It’s just a ScreenGui in the StarterGui folder.

Alright, and the script is a local script parented to the GUI?

1 Like

Yes it is (char limit why bruh)

local decoder = require(game.ReplicatedStorage.ClientDecoder)
local textbox = script.Parent.TextBox
local textbutton = script.Parent.TextButton
local textlabel = script.Parent.TextLabel
textbutton.MouseButton1Click:Connect(function()
	print("CLICKED")
	local finaltext
	local text = textbox.Text
	local letters = string.gmatch(text, ".")
	for j = 1, 26 do
		local key = decoder.KeyboardUp[j]
		local uppercase = decoder.UpperKeywords[j]
		local lowercase = decoder.LowerKeywords[j]
		for i in letters do
			if i == key then
				finaltext = finaltext..uppercase
				textlabel.Text = finaltext
				if finaltext == nil then
					finaltext = uppercase
				else
					finaltext = finaltext .. uppercase
				end
			end
		end
	end
end)
string.gmatch(text, ".")

This was the change I made, before you weren’t actually searching for any patterns within the subject string.

I already tried this. Didn’t work as I said.

local decoder = require(game.ReplicatedStorage.ClientDecoder)
local textbox = script.Parent.TextBox
local textbutton = script.Parent.TextButton
local textlabel = script.Parent.TextLabel
textbutton.MouseButton1Click:Connect(function()
	print("CLICKED")
	local finaltext
	local text = textbox.Text
	local letters = string.gmatch(text, ".")
	for j = 1, 26 do
		local key = decoder.KeyboardUp[j]
		local uppercase = decoder.UpperKeywords[j]
		local lowercase = decoder.LowerKeywords[j]
		for i, v in pairs(letters) do
			if v == key then
				finaltext = finaltext..uppercase
				textlabel.Text = finaltext
				if finaltext == nil then
					finaltext = uppercase
				else
					finaltext = finaltext .. uppercase
				end
			end
		end
	end
end)
1 Like

I’m getting this error:

18:53:51.213  Players.Dr_Exabyte1010.PlayerGui.Decode.DecodeFrame.LocalScript:14: invalid argument #1 to 'pairs' (table expected, got function)  -  Client - LocalScript:14

How do I fix this? (Sorry this is the first time I used string.gmatch)

local decoder = require(game.ReplicatedStorage.ClientDecoder)
local textbox = script.Parent.TextBox
local textbutton = script.Parent.TextButton
local textlabel = script.Parent.TextLabel
textbutton.MouseButton1Click:Connect(function()
	print("CLICKED")
	local finaltext
	local text = textbox.Text
	for j = 1, 26 do
		local key = decoder.KeyboardUp[j]
		local uppercase = decoder.UpperKeywords[j]
		local lowercase = decoder.LowerKeywords[j]
		for letter in string.gmatch(text, ".") do
			if v == key then
				finaltext = finaltext..uppercase
				textlabel.Text = finaltext
				if finaltext == nil then
					finaltext = uppercase
				else
					finaltext = finaltext .. uppercase
				end
			end
		end
	end
end)

If this doesn’t work there’s likely some issue with your code & I’ll need to dedicate a little extra time looking at exactly what it does to debug it.

Hi. the problem is that the gmatch return iterator function does not restart automatically (it only runs for j = 1). So you have to run gmatch for each j. Also, the code is a bit simpler if you give an initial value to finaltext (finaltext = “”).

local decoder = require(game.ReplicatedStorage.ClientDecoder)
local textbox = script.Parent.TextBox
local textbutton = script.Parent.TextButton
local textlabel = script.Parent.TextLabel
textbutton.MouseButton1Click:Connect(function()
	print("CLICKED")
	local finaltext = ""
	local text = textbox.Text
	--local letter = string.gmatch(text, ".")
	for j = 1, 26 do
		local key = decoder.KeyboardUp[j]
		local uppercase = decoder.UpperKeywords[j]
		local lowercase = decoder.LowerKeywords[j]
		for i in string.gmatch(text, ".") do
			if i == key then
				finaltext = finaltext..uppercase
				textlabel.Text = finaltext
				--if finaltext == "" then
				--	finaltext = uppercase
				--else
				--	finaltext = finaltext .. uppercase
				--end
			end
		end
	end
end)