Trying to change textlabels inside of frame

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)

Because you are looping through taks1 and using the print statement inside of the second loop frm. Try putting the print function inside of frm loop so basically for every task you are doing a check looking at every frm inside of frm and printing v which just means it’s gonna say the same value again but the attribute maybe diffrent. This is what I’ve been saying befote

Aren’t you basically just doing what I did? Then why does your code looks so complicated ?
Pre-Cautions are needed but make sure you don’t have too much pre-cautions these may just be a cause to a new problem.

Like for example, Why are you looping through the frm to see if Its a TaskFrame and then rechecking with local Actual = frm:FindFirstChild("Task"..strNumber). If there is by chance a duplicate Actual frame it might just get that and v2 would not be the same even tho the Name of Actual would be the same.
And then you are looping through Tasks1 to see if Its the right Task number inside of those loops, which might cause lag to people with a bad connection or a bad device if there’s alot of values to work with.

Instead what I did is to first loop through tasksFrame and see if it’s visible or if it contain the name of “Task” and is a frame then check for the task inside of the Task Folder. I am only doing one loop, the frm and then just seeing If i can find the same name as the task frame (like ‘Task1’ or ‘Task2’) and seting the name, desc.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.