Hmm, okay. I finally managed to make it work. but it still prints alot lot of times. even though i removoed the tables that is not important and could cause it to print alot
local event = game:GetService("ReplicatedStorage").Events:WaitForChild("Tasks")
local plr = game:GetService("Players").LocalPlayer
local deb = false
local frm = plr.PlayerGui:WaitForChild("ObjNew").Frame.Tasks
local Progress = 1
local TasksModule = require(game:GetService("ReplicatedStorage").Modules:WaitForChild("TasksLocated"))
event.OnClientEvent:Connect(function(Tasks,NPCName)
local ActualTask
--Function to get the table inside the module
local function Get()
for index,value in TasksModule do
print(index,value)
if index == NPCName then
local IDKTHEName = value
for name, value2 in pairs(IDKTHEName) do
if tonumber(name) and tonumber(name) == Progress then
ActualTask = value2
return value2
else
end
end
end
end
end
if deb then return end
deb = true
local side
----------------------------------------------------------
if Get() then
--Sets Frame name to the ObjectiveName
frm.Parent.Title.Text = ActualTask.ObjName
--Gets Tasks Table with number of tasks in it.
local Tasks1 = ActualTask.Tasks
local TasksNum = 0
for i, v in pairs(Tasks1) do
TasksNum += 1
end
if not Tasks or typeof(Tasks) ~= "Instance" then warn("Return due to missing Argument Tasks [Instance Type Needed]") return end
if not TasksNum or typeof(TasksNum) ~= "number" then TasksNum = 0 warn("Missing Argument TasksNum or not a number type. Setting to Default. Which is 0.") end
--Runs code for children of the Objective Frame
for i2,v2 in frm:GetChildren() do
if not v2:IsA("Frame") or not v2.Name:match("Task") then continue end
--Gets the number from the frame
local str = string.split(v2.Name, "Task")[2]
local strNumber = tonumber(str)
--For checking purposes i guess
local Actual = frm:FindFirstChild("Task"..strNumber)
if Actual ~= v2 then continue end
if tonumber(string.match(v2.Name, "%d+")) > TasksNum or TasksNum < 1 then v2.Visible = false continue end
--Finds the Task table inside Main Tasks Frame and if it does find it then it changes frame's textlabels text to the relative values
for i,v in pairs(Tasks1) do
--If number is number
if i == str then
v2.TaskName.Text = ((v.Required == true) and v.Title.." [REQUIRED]") or v.Title
v2.TaskRequired.Text = v.Desc
v2:SetAttribute("Task",string.match(v2.Name, "%d+"))
if v2.Visible ~= true then v2.Visible = true end
print(v, "Task Attribute has been set to", v2:GetAttribute("Task"))
deb = false
end
end
end
end
end)