I’ve made multiple threads on this gosh darn problem I have. Optimization/Readability of code. I’ve gotten loads of helpful tips from people I’ve talked to, to scouring the DevForum and looking at posts having the same problem I do. Although, my knowledge of coding is lackluster at best and I guess my mind was high when I wrote this code that I physically cannot process.
‘What Kinda Script Is This’ Script:
for i, NPCs in pairs(npcFolder:GetChildren()) do
if NPCs.Name == "Test" then
local welcomeTexts = {
"hey",
"hello",
"how's the trip here?",
}
local goodbyeTexts = {
"see you later.",
"bye",
"take care mate.",
"alright, see ya.",
}
NPCs.NPC_Prompt.ProximityPrompt.Triggered:Connect(function()
camCFrame = currentCam.CFrame
NPCs.NPC_Prompt.ProximityPrompt.Enabled = false
currentCam.CameraType = Enum.CameraType.Scriptable
Humanoid.AutoRotate = false
Humanoid.WalkSpeed = 0
task.wait()
Random_Dialog = math.random(1,3)
npcChange(NPCs.Name, NPCs.NPC_Cam.CFrame)
frame.Visible = true
frameTweenIn:Play()
task.wait(0.35)
nameTweenIn:Play()
typeWrite(text, welcomeTexts[math.random(#welcomeTexts)])
end)
text.Activated:Connect(function()
NPC_Amount += 1
if Random_Dialog == 1 then
if NPC_Amount == 1 then
typeWrite(text, "testing text1.")
elseif NPC_Amount == 2 then
typeWrite(text, "testing text2.")
elseif NPC_Amount == 3 then
typeWrite(text, "testing text3.")
elseif NPC_Amount == 4 then
typeWrite(text, goodbyeTexts[math.random(#goodbyeTexts)])
task.wait(2)
frameTweenOut:Play()
nameTweenOut:Play()
text.Text = ""
name.Text = ""
NPC_Amount = 1
npcChange("", camCFrame)
NPCs.NPC_Prompt.ProximityPrompt.Enabled = true
currentCam.CameraType = Enum.CameraType.Custom
camCFrame = nil
end
Random_Dialog = 0
elseif Random_Dialog == 2 then
if NPC_Amount == 1 then
typeWrite(text, "testing text1.")
elseif NPC_Amount == 2 then
typeWrite(text, "testing text2.")
elseif NPC_Amount == 3 then
typeWrite(text, "testing text3.")
elseif NPC_Amount == 4 then
typeWrite(text, goodbyeTexts[math.random(#goodbyeTexts)])
task.wait(2)
frameTweenOut:Play()
nameTweenOut:Play()
text.Text = ""
name.Text = ""
NPC_Amount = 1
npcChange("", camCFrame)
NPCs.NPC_Prompt.ProximityPrompt.Enabled = true
currentCam.CameraType = Enum.CameraType.Custom
camCFrame = nil
end
Random_Dialog = 0
elseif Random_Dialog == 3 then
if NPC_Amount == 1 then
typeWrite(text, "testing text1.")
elseif NPC_Amount == 2 then
typeWrite(text, "testing text2.")
elseif NPC_Amount == 3 then
typeWrite(text, "testing text3.")
elseif NPC_Amount == 4 then
typeWrite(text, goodbyeTexts[math.random(#goodbyeTexts)])
task.wait(2)
frameTweenOut:Play()
nameTweenOut:Play()
text.Text = ""
name.Text = ""
NPC_Amount = 1
npcChange("", camCFrame)
NPCs.NPC_Prompt.ProximityPrompt.Enabled = true
currentCam.CameraType = Enum.CameraType.Custom
camCFrame = nil
end
Random_Dialog = 0
end
end)
end
end
It works, but I just…
I’ve started with tables and putting all possible dialogue in their respective tables. Though my brain cannot continue due to both of my braincells not having the capacity to write decent code oh my GOSH.
local wlcm_N_gdby_Texts = {
welcomeTexts = {
"hey",
"sup.",
"hello.",
"how's the trip here?",
},
goodbyeTexts = {
"see you later.",
"bye.",
"take care.",
"alright, see ya.",
}
}
local dialogPaths = {
Path1 = {
[1] = "blah blah",
[2] = "blah blah",
[3] = "blah blah"
},
Path2 = {
[1] = "blah blah",
[2] = "blah blah",
[3] = "blah blah"
},
Path3 = {
[1] = "blah blah",
[2] = "blah blah",
[3] = "blah blah"
},
Path4 = {
[1] = "blah blah",
[2] = "blah blah",
[3] = "blah blah"
},
}
please help me i’ve been stuck with this problem for over 3 hours now