How could I make an undo and redo system

I have been trying to make an undo and redo system for my drawing game, I can’t get anything working good; I have tried with using tables. Each time they draw an line I insert into the table that they placed one and their position so I can undo and redo it; and Color wheel I insert the Color that was returned but nothing I have tried works very well there are many bugs.