Help with Replacing a string by letter

the script for those who want to recreate something like this

how to do it

  1. Create a remoteEvent inside ReplicatedStorage then name it “CatchPlrMessage”

  2. put UIScript like this
    image

  3. Put ServerScript inside ServerScriptService

  4. You done

GUI script (localScript)
local TweenService = game:GetService("TweenService")

local Msg = " "
local Text = script.Parent.Frame.TextLabel

local function GetTotalLetterInMessage(message : string)
	return #message
end

local function CreateGiberish()
	local Giberish = ""
	for i = 1, GetTotalLetterInMessage(Msg) do
		local RandomNumber = math.random(1, 2)
		if RandomNumber == 1 then
			Giberish = Giberish .. string.upper(string.char(math.random(97, 122)))
		else
			Giberish = Giberish .. string.char(math.random(97, 122))
		end
	end
	return Giberish
end

local function Replacing()
	local TextToReplace = Text.Text
	if string.len(TextToReplace) <= 0 then
		warn("You can't replace empty text!")
		return
	end
	Text.Parent.Visible = true
	local chars = string.split(TextToReplace, "")
	local num = 0

	while task.wait(0.03) do
		num += 1

		local newText = string.sub(Msg, 0, num)
		for i = num+1, #Msg do
			newText ..= chars[math.random(1,#chars)]
		end

		Text.Text = newText

		if num >= GetTotalLetterInMessage(Msg) then
			break
		end
	end
end

game:GetService("ReplicatedStorage").CatchPlrMessage.OnClientEvent:Connect(function(msg)
	Msg = msg
	Text.Parent.Visible = true
	Text.Text =  CreateGiberish()
	Text.MaxVisibleGraphemes = 0
	
	local tween = TweenService:Create(Text, TweenInfo.new(string.len(msg)/50), {MaxVisibleGraphemes = utf8.len(Text.ContentText)})
	tween:Play()
	tween.Completed:Wait()
	Replacing()
	Text.MaxVisibleGraphemes = -1
end)
ServerScript for detecting player chat message
local plr = game:GetService("Players")

plr.PlayerAdded:Connect(function(Player)

	Player.Chatted:Connect(function(msg)

		game:GetService("ReplicatedStorage").CatchPlrMessage:FireClient(Player, msg)
		
	end)

end)
1 Like