[SOLVED] Need help getting a random index from a string and adding it into a textlabel

I am trying to make a Obfuscator effect, however I am not sure how to get a random index from a string and add it into text.

Expected behaviour: A random string will be generated in the length of the sentence (another script.)

Actual behavior: Script prints however it doesn’t change the text.

Scripts:
ReplicatedStorage Modulescript

local ObfuscatorList = {}
local Characters = "ABCEFGHIJKLMNOPQRSTUVWYZabcefghijklmnopqrstyvwyz1234567890!@#$%^&*()_+`~<>|{}[];:"

function ObfuscatorList.Obfuscator(GuiObject, TextLabel, DelayBetweenChars)
	
	GuiObject.Visible = true
	
	local Text = TextLabel
	local Length = GuiObject.Text
	GuiObject.Text = Text
	local CharacterIndex = 0
	
	for first, last in utf8.graphemes(Text) do
		CharacterIndex += 1
		local RandomIndex = math.random(0, string.len(Characters))
		Text = TextLabel:gsub("<br%s*/>", "\n")
		Text:gsub("<[^<>]->", "")
		GuiObject.Text = Characters.sub(math.random(0, string.len(Text)), string.len(Text))
		GuiObject.MaxVisibleGraphemes = CharacterIndex
		print("Obfuscating")
		wait(DelayBetweenChars)
		
   end
end

return ObfuscatorList

GUI script:

local Players = game:GetService("Players").LocalPlayer

local TweenService = game:GetService("TweenService")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local AnimateUi = require(ReplicatedStorage:WaitForChild("AnimateUi"))

local Obfuscator = require(ReplicatedStorage:WaitForChild("Obfuscator"))

local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))


local TV = script.Parent

local MusicThing = TV["Lobby Music"]

	local StartButton = script.Parent.Image.Continue
	local TextJoin = script.Parent.Image.TextJoin

	local Controls = PlayerModule:GetControls()
    Controls:Disable()
	MusicThing:Play()

	local TextText = "Welcome, " .. Players.Name
	StartButton.Text = "Start"
	local TextMessage = Obfuscator.Obfuscator(TextJoin, TextText, 0.1)
	
	TV.Image.Continue.BackgroundTransparency = 1
	TV.BackgroundTransparency = 1
	local TweenInfoScript = TweenInfo.new(
		1,
		Enum.EasingStyle.Quad,
		Enum.EasingDirection.InOut,
		0,
		false,
		0
    )
	
	
	StartButton.MouseButton1Click:Connect(function()		
		repeat	  
          local CameraContinue = TV.Image.Continue.Camera		
		  TV.Image.Transparency += 0.2
		  TV.Image.Continue.Transparency += 0.2
		  CameraContinue.ImageTransparency += 0.2
		  TV.Image.TextJoin.Transparency += 0.2
		  task.wait(0.1)
		until CameraContinue.ImageTransparency == 1
		script.Parent:Destroy()
        Controls:Enable()
end)

What Dev console saying?
I need to know that.

Getting a random item from the string and adding it is very simple, just needs simple understanding of strings

local Text = "change me to your string"
local TextLabel = --give Location

local RandomNumber = math.random(1 , #Text)
RandomNumber = math.round(RandomNumber) --make sure its a full number.

local randomString = string.sub(Text , RandomNumber - 1 , RandomNumber) --returns 1 letter

--adding it to textLabel
TextLabel.Text = TextLabel.Text..randomString
print(TextLabel.Text , randomString)
1 Like