I made a dialogue class (WIP) and I tried testing it but I came with an issue I normally never get it.
I am guessing this is a really small error that is not very noticeable to me
Dialogue:39: attempt to index nil with 'Name'
Class Module:
function Dialogue.new(NPC: Instance, DialogueText: string, QuestOn: boolean, QuestName)
local self = setmetatable({},Dialogue)
self.NPC = NPC
self.Text = DialogueText
self.QuestOn = QuestOn
self.QuestName = QuestName
print(self.NPC) -- it works here but it doesnt work on dialogue:createui
return self
end
function Dialogue:CreateUI() -- screengui is default disabled
local ScreenGUI = Instance.new("ScreenGui")
ScreenGUI.Name = "Dialogue "..self.NPC.Name -- the issue is right here
local MainFrame = Instance.new("Frame")
MainFrame.AnchorPoint = Vector2.new(0.5,0.5)
MainFrame.Position = UDim2.new(0.5,0,0.5,0)
MainFrame.Size = UDim2.new(1,0,1,0)
MainFrame.BackgroundColor3 = Color3.new(0,0,0)
MainFrame.BackgroundTransparency = 0.2
local NameFrame = Instance.new("Frame")
NameFrame.AnchorPoint = Vector2.new(0.,0.5)
NameFrame.Position = UDim2.new(0.241,0,0.619,0)
NameFrame.Size = UDim2.new(0.195,0,0.07,0)
local NameText = Instance.new("TextLabel")
NameText.AnchorPoint = Vector2.new(0.5,0.5)
NameText.Position = UDim2.new(0.5,0,0.5,0)
NameText.Size = UDim2.new(1,0,1,0)
NameText.Text = self.NPC.Name
local TextFrame = Instance.new("Frame")
TextFrame.AnchorPoint = Vector2.new(0.,0.5)
TextFrame.Position = UDim2.new(0.536,0,0.744,0)
TextFrame.Size = UDim2.new(0.72,0,0.229,0)
local Yes = Instance.new("Frame")
Yes.AnchorPoint = Vector2.new(0.,0.5)
Yes.Position = UDim2.new(0.353,0,0.915,0)
Yes.Size = UDim2.new(0.354,0,0.07,0)
local YesText = Instance.new("TextLabel")
YesText.AnchorPoint = Vector2.new(0.5,0.5)
YesText.Position = UDim2.new(0.5,0,0.5,0)
YesText.Size = UDim2.new(1,0,1,0)
YesText.TextColor3 = Color3.fromRGB(112, 255, 111)
YesText.Font = "Source Sans Pro" or Enum.Font.SourceSans
YesText.TextScaled = true
YesText.Text = "YES"
local No = Instance.new("Frame")
No.AnchorPoint = Vector2.new(0.,0.5)
No.Position = UDim2.new(0.719,0,0.915,0)
No.Size = UDim2.new(0.354,0,0.07,0)
local NoText = Instance.new("TextLabel")
NoText.AnchorPoint = Vector2.new(0.5,0.5)
NoText.Position = UDim2.new(0.5,0,0.5,0)
NoText.Size = UDim2.new(1,0,1,0)
NoText.TextColor3 = Color3.fromRGB(250, 67, 46)
NoText.Font = "Source Sans Pro" or Enum.Font.SourceSans
NoText.TextScaled = true
YesText.Text = "NO"
local Ok = Instance.new("Frame")
Ok.AnchorPoint = Vector2.new(0.,0.5)
Ok.Position = UDim2.new(0.536,0,0.915,0)
Ok.Size = UDim2.new(0.72,0,0.07,0)
local OkText = Instance.new("TextLabel")
OkText.AnchorPoint = Vector2.new(0.5,0.5)
OkText.Position = UDim2.new(0.5,0,0.5,0)
OkText.Size = UDim2.new(1,0,1,0)
OkText.TextColor3 = Color3.fromRGB(112, 255, 111)
OkText.Font = "Source Sans Pro" or Enum.Font.SourceSans
OkText.TextScaled = true
OkText.Text = "OK"
-- DEFAULT BOOLEANS (DONT CHANGE)
ScreenGUI.Enabled = false
if not self.QuestOn then
Yes.Visible = false -- yes for quest
No.Visible = false -- no for quest
end
MainFrame.Parent = ScreenGUI
NameFrame.Parent = MainFrame
NameText.Parent = MainFrame
TextFrame.Parent = MainFrame
Yes.Parent = MainFrame
YesText.Parent = Yes
No.Parent = MainFrame
NoText.Parent = No
Ok.Parent = MainFrame
OkText.Parent = Ok
for i,v in pairs(MainFrame:GetChildren()) do
if v:IsA("Frame") then
local UICorner = Instance.new("UICorner")
local UIStroke = Instance.new("UIStroke")
UICorner.Parent = v
UIStroke.Parent = v
v.BackgroundColor3 = Color3.new(0,0,0)
v.BackgroundTransparency = 0.2
end
end
return ScreenGUI
end
How I started the dialogue (Client)
v.ClickDetector.MouseClick:Connect(function()
local NewDialogue = Dialogue.new(v,v.Dialogue.Text,false,nil)
NewDialogue:Start()
end)
also createui is ran somewhere, i just didnt show the full class