so i have a dialogue script but apparently when i try to provide diag[index]
it says attempt to index nil with number
???
idk whats going on heres the script and below script is error and printed table:
-- rescripted was here :)
-- // SERVICES
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- // VARIABLES
local mainFrame = script.Parent:WaitForChild("MainFrame")
local charImage = mainFrame:WaitForChild("Guy")
local charName = mainFrame:WaitForChild("Yapper")
local dialouge = mainFrame:WaitForChild("Yapping")
local options = mainFrame:WaitForChild("Options")
local template = script:WaitForChild("Template")
local typewriter = require(script:WaitForChild("TypewriterModule"))
local dialogueMessages = require(script:WaitForChild("DialogueMessages"))
-- // FUNCTIONS
local function Dialogue(name: string, text: string, imageId: number, optionTable: {any})
charImage.Image = `rbxassetid://{imageId}`
charName.Text = name
for _, option in options:GetChildren() do
if not option:IsA("GuiButton") then continue end
option:Destroy() -- destroys every option before creating new options
end
typewriter.typewrite(dialouge, text)
for _, option in optionTable do
local newOption = template:Clone()
newOption.Text = option[1]
newOption.Parent = options
end
return optionTable
end
local function StartDialogue(npc): {any}
mainFrame.Parent.Enabled = true
npc:FindFirstChild("HumanoidRootPart"):FindFirstChildOfClass("ProximityPrompt").Enabled = false
return Dialogue(
npc.Name,
dialogueMessages[npc.Name]["NPC"][1],
dialogueMessages[npc.Name]["ImageId"],
dialogueMessages[npc.Name]["Options"][1]
)
end
local function NextLine(index, handler, npc): boolean
if handler == "close" then
mainFrame.Parent.Enabled = false
npc:FindFirstChild("HumanoidRootPart"):FindFirstChildOfClass("ProximityPrompt").Enabled = true
return true
end
print(dialogueMessages[npc.Name])
Dialogue(
npc.Name,
dialogueMessages[npc.Name]["NPC"][index],
dialogueMessages[npc.Name]["ImageId"],
dialogueMessages[npc.Name]["Options"][index]
)
return false
end
local function addProximity(model: Model)
assert(model:IsA("Model"), `invalid argument #1 to addProximity (Model expected, got {typeof(model)})`)
print(model.Name)
local prox = Instance.new("ProximityPrompt")
prox.ActionText = "Talk"
prox.KeyboardKeyCode = Enum.KeyCode.F
prox.RequiresLineOfSight = false
prox.MaxActivationDistance = 5
prox.Parent = model:FindFirstChild("HumanoidRootPart")
local debounce = false
local index = 1
local diag
prox.Triggered:Connect(function()
diag = StartDialogue(model)
end)
options.ChildAdded:Connect(function(option)
if not option:IsA("GuiButton") then return end
option.MouseButton1Click:Connect(function()
if (charName.Text ~= model.Name) and debounce then return end
debounce = true
index += 1
print(diag[index], diag, index) -- Line 91
local reset = NextLine(index, diag[index][2], model)
index = reset and 1
task.wait(0.5)
debounce = false
end)
end)
end
for _, npc in workspace:WaitForChild("Tidefall Bay"):WaitForChild("NPCS"):GetChildren() do
if not npc:IsA("Model") then continue end
addProximity(npc)
end