Tables Values not changing

Im kinda new to metatables and modules so this might be easy or it could be something nothing to do with modules or metatables. When I call InterpretInput it always prints the exact same thing. Why?

function module.CreateBookTables(pages,author)	
	--PAGE CONSTRUCT
	local pageTable = {}
	for i=1,pages do
		pageTable[i]={
			Display = workspace:WaitForChild("Page1").SurfaceGui.TextBox;
			Text = "";
			Page = i;
		}
	end
	
	--DATA CONSTRUCT
	local dataTable = {
		LastInput = Enum.KeyCode.Unknown;
		LastInputTick = tick();
		BoldToggle = false;
		ItalicToggle = false;
	}
	
	--BOOK CONSTRUCT
	local bookTable = {
		PageTable = pageTable;
		DataTable = dataTable;
		Author = author;
		Title = "";
	}
	
	local metaBookTable = setmetatable(bookTable,module)
	return metaBookTable
end

function module:InterpretInput(input,gpEvent)
	local dataTable = self.DataTable
	local lastInput = self.DataTable.LastInput
    print(lastInput)
end

Still couldnt find a solution have been editing it for like the past hour. :thinking:

Well. You aren’t actually editing a table. You are setting local variables to what the table has in it. Those changes are discarded once the function ends. You’ll need to write to self instead of just read from it to keep those changes. So it’s the same value each time because it’s not changed.

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