I have been coding for a while now but one of the main things I struggle with is repeating a lot of stuff in the code rather than trying to make it less work for me to type. Here is an example:
local part = script.Parent
local seq = 1
part.Changed:connect(function(property)
local text = script.Parent:FindFirstChild(seq).Top.Value
local count = string.len(text)
for i = 1, count, 1 do
script.Parent.Parent.Parent.Text.TextLineOne.Text = string.sub(text, 1, i)
wait(0.1)
end
local text2 = script.Parent:FindFirstChild(seq).Bottom.Value
local count2 = string.len(text2)
for i = 1, count2, 1 do
script.Parent.Parent.Parent.Text.TextLineTwo.Text = string.sub(text2, 1, i)
wait(0.1)
end -- (NEW ONE BELOW)
if part:FindFirstChild(seq+1) ~= nil then
seq = seq + 1
local text = script.Parent:FindFirstChild(seq).Top.Value
local count = string.len(text)
for i = 1, count, 1 do
script.Parent.Parent.Parent.Text.TextLineOne.Text = string.sub(text, 1, i)
wait(0.1)
end
local text2 = script.Parent:FindFirstChild(seq).Bottom.Value
local count2 = string.len(text2)
for i = 1, count2, 1 do
script.Parent.Parent.Parent.Text.TextLineTwo.Text = string.sub(text2, 1, i)
wait(0.1)
end
else
end
end)
This wouldn't even be all of it if I didn't condense it. I'm trying to make a dialog system that appears clean. I don't want to keep repeating the same code over and over when all I am doing is changing one value. Please help!

3 comments
This works great, except the game freezes after the last line is played. How would I fix that?
Nevermind, figured it out. Had to add a wait after the while true do.
Oops, I fixed it a different way. I meant to stop the loop when
sourcewasnil