How do i only make a new log if something has changed

a guy fixed one of my pices of code but i forgot to ask about not making it make alog if nothing changed.

local function CreateUpdateLog()
	local LS = game.Workspace:WaitForChild("LogsScreen"):WaitForChild("SurfaceGui"):WaitForChild("BG")
	
	local L1 = LS.TEMP.About:Clone()
	L1.About.Text = "Heres some things we changed!"
	L1.Parent = LS.About
	L1.Visible = true

	local L2 = LS.TEMP.Date:Clone()
	L2.Date.Text = module.Date
	L2.Parent = LS.Date
	L2.Visible = true

	-- Complicated stuff :(
	local L3 = LS.TEMP.Info:Clone()
	L3.Parent = LS.Info
	local Placement = L3.List
	local Item = LS.TEMP.ChangedLabel
	L3.Visible = true

	for key, oldValue in pairs(LastInstanceOfWRLDDATA) do
		local newValue = module[key]
		if newValue ~= oldValue then
			local L4 = Item:Clone()
			L4.Text = "Changed "..key.." To: "..tostring(newValue)
			L4.Parent = Placement
			L4.Visible = true
		end
	end
	
	for key, value in pairs(module) do
		if key == "Age" or key == "Pop" or key == "Danger" or key == "Economy" or key == "AvrgMood" or key == "Wants" or key == "Anger" then
			LastInstanceOfWRLDDATA[key] = value
		end
	end

	if #LS.About:GetChildren() > 9 then
		for _, v in LS.About:GetChildren() do
			if v:IsA("Frame") then
				v:Destroy()
			end
		end

		for _, v in LS.Info:GetChildren() do
			if v:IsA("Frame") then
				v:Destroy()
			end
		end

		for _, v in LS.Date:GetChildren() do
			if v:IsA("Frame") then
				v:Destroy()
			end
		end
	end
end

Thats the code he gave me, how would i make it not create a new log if nothing is new?

1 Like

Did you want it to clear old logs if changes were detected? Iā€™m a bit confused.

1 Like

so if there were no new changes then i dont want a new log made, otherwise make a new log

1 Like

Is this what you want?

local LastInstanceOfWRLDDATA = {}  -- Initialize the table to keep track of last data

local function CreateUpdateLog()
    local LS = game.Workspace:WaitForChild("LogsScreen"):WaitForChild("SurfaceGui"):WaitForChild("BG")
    
    local changesDetected = false  -- Flag to track if any changes were detected

    -- Check for changes in module data
    for key, oldValue in pairs(LastInstanceOfWRLDDATA) do
        local newValue = module[key]
        if newValue ~= oldValue then
            changesDetected = true
            break  -- Exit the loop early if any change is detected
        end
    end

    -- If no changes detected, exit without creating a new log
    if not changesDetected then
        return
    end

    -- Clear old logs if necessary
    if #LS.About:GetChildren() > 9 then
        for _, v in ipairs(LS.About:GetChildren()) do
            if v:IsA("Frame") then
                v:Destroy()
            end
        end

        for _, v in ipairs(LS.Info:GetChildren()) do
            if v:IsA("Frame") then
                v:Destroy()
            end
        end

        for _, v in ipairs(LS.Date:GetChildren()) do
            if v:IsA("Frame") then
                v:Destroy()
            end
        end
    end

    -- Create new logs for detected changes
    local L1 = LS.TEMP.About:Clone()
    L1.About.Text = "Here are some things we changed!"
    L1.Parent = LS.About
    L1.Visible = true

    local L2 = LS.TEMP.Date:Clone()
    L2.Date.Text = module.Date
    L2.Parent = LS.Date
    L2.Visible = true

    local L3 = LS.TEMP.Info:Clone()
    L3.Parent = LS.Info
    local Placement = L3.List
    local Item = LS.TEMP.ChangedLabel
    L3.Visible = true

    for key, oldValue in pairs(LastInstanceOfWRLDDATA) do
        local newValue = module[key]
        if newValue ~= oldValue then
            local L4 = Item:Clone()
            L4.Text = "Changed "..key.." To: "..tostring(newValue)
            L4.Parent = Placement
            L4.Visible = true
        end
    end
    
    -- Update LastInstanceOfWRLDDATA with current module data
    for key, value in pairs(module) do
        if key == "Age" or key == "Pop" or key == "Danger" or key == "Economy" or key == "AvrgMood" or key == "Wants" or key == "Anger" then
            LastInstanceOfWRLDDATA[key] = value
        end
    end
end

1 Like

what exactly does this do?
char limit

just tried this and its not making any logs at all