So, im making a dailog GUI for my game, and im probably doing it in a pretty bad way. Right now, everything works up until you try to click on one of the responses. I believe this is because im trying to run the modules function inside of the function, but thats what i want to do and i dont know how else to do it. Heres the code and the descendants:
local module = {}
module.Apply_Properties = function(label: TextLabel, properties: Folder)
for _, v in pairs(properties:GetChildren()) do
v:Clone().Parent = label
end
end
module.End = function(gui, player)
gui:Destroy()
player:SetAttribute('talking', false)
end
module.Talk = function(text_parent, text: TextLabel, gui: ScreenGui, player: Player)
local talk_amount = #text_parent:GetChildren()
for i = 1, talk_amount do
for a = 1, #text_parent['Talk'..i].Value do
text.Text = string.sub(text_parent['Talk'..i].Value, 1, a)
wait(0.05)
end
task.wait(2)
if i == talk_amount then
if #text_parent['Talk'..i]:GetChildren() == 0 then
module.End(gui, player)
end
if #text_parent['Talk'..i]:GetChildren() ~= 0 then
text.Text = ""
for b = 1, #text_parent['Talk'..i]:GetChildren() do
task.spawn(function()
local response = script.Response:Clone()
response.Name = 'Response'..b
response.Text = text_parent['Talk'..i]['Response'..b].Value
response.Parent = gui.Frame.Responses
response.Activated:Connect(function()
module.Talk(response, text, gui, player)
end)
end)
end
end
end
end
end
module.Active = function(slug: string, player: Player)
if player:GetAttribute('talking') ~= true then
player:SetAttribute('talking', true)
local main_folder = script:FindFirstChild(slug)
local properties = main_folder.Properties
local GUI = script.Dailogue:Clone()
GUI.Parent = player.PlayerGui
local text_parent = main_folder.Text
local text = script.Text:Clone()
text.Text = ""
text.Parent = GUI.Frame
module.Apply_Properties(text, properties)
module.Talk(text_parent, text, GUI, player)
end
end
return module