Trying to make a capacitive sensor, encountering errors in sketch

Hiya Forum! I'm trying to make a basic capacitive sensor, but I'm encounter some errors in the code. I copied the code from this instructable: https://www.instructables.com/How-To-Use-Touch-Sensors-With-Arduino/ and installed the capacitivesensor library, but it's coming up with a lot of errors in the sketch. Any help deciphering would be great as I'm not experienced in C++. Here's the sketch & errors:

#include <CapacitiveSensor.h>

int led = 42;                                          //change '42' to any desired pin...long time = 0;
int state = HIGH;

boolean yes;
boolean previous = false;

int debounce = 200;

CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired// To add more sensors...//CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil//CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foilvoidsetup()                    
{
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);  //Calibrate the sensor... 
   pinMode(led, OUTPUT);
}

voidloop()                    
{
    long total1 =  cs_4_2.capacitiveSensor(30);
    
    if (total1 > 60){yes = true;}
    else {yes = false;}    
    
    // to toggle the state of state
    if(yes == true && previous  == false && millis() - time>debounce){
      
       if(state == LOW){
         state = HIGH;
       }
       else 
         state = LOW;
         time = millis();     
       
    }
       
   
      digitalWrite(led, state);
      previous = yes;

      Serial.println(millis()-time);
      delay(10);


}
C:\Users\liamj\AppData\Local\Temp\.arduinoIDE-unsaved20241027-9808-l04jow.yl7mk\sketch_nov27a\sketch_nov27a.ino:12:1: error: expected unqualified-id before '{' token
 {
 ^
C:\Users\liamj\AppData\Local\Temp\.arduinoIDE-unsaved20241027-9808-l04jow.yl7mk\sketch_nov27a\sketch_nov27a.ino:17:12: error: expected constructor, destructor, or type conversion before ';' token
 voidloop()
            ^
C:\Users\liamj\AppData\Local\Temp\.arduinoIDE-unsaved20241027-9808-l04jow.yl7mk\sketch_nov27a\sketch_nov27a.ino: In function 'int voidloop()':
C:\Users\liamj\AppData\Local\Temp\.arduinoIDE-unsaved20241027-9808-l04jow.yl7mk\sketch_nov27a\sketch_nov27a.ino:25:56: error: 'time' was not declared in this scope
     if(yes == true && previous  == false && millis() - time>debounce){
                                                        ^~~~
C:\Users\liamj\AppData\Local\Temp\.arduinoIDE-unsaved20241027-9808-l04jow.yl7mk\sketch_nov27a\sketch_nov27a.ino:25:56: note: suggested alternative: 'tone'
     if(yes == true && previous  == false && millis() - time>debounce){
                                                        ^~~~
                                                        tone
C:\Users\liamj\AppData\Local\Temp\.arduinoIDE-unsaved20241027-9808-l04jow.yl7mk\sketch_nov27a\sketch_nov27a.ino:40:31: error: 'time' was not declared in this scope
       Serial.println(millis()-time);
                               ^~~~
C:\Users\liamj\AppData\Local\Temp\.arduinoIDE-unsaved20241027-9808-l04jow.yl7mk\sketch_nov27a\sketch_nov27a.ino:40:31: note: suggested alternative: 'tone'
       Serial.println(millis()-time);
                               ^~~~
                               tone

exit status 1

Compilation error: expected unqualified-id before '{' token

Compilation error: expected unqualified-id before '{' token

Thanks so much!

Instructables screwed up the formatting and a whole bunch of lines got glommed into one; including the top of the setup() function.

If that's any indication of how the rest of the sketch goes, you've got your work cut out for you trying to fix that mess.

You pulled something out of the sewer and you want what?

Wow, you installed the cap sense library. To something with voidloop(). I can tell you're not experienced in C++, there are beginners with more experience.

Did you get help from ChatGPT? Or are you ChatGPT? You might as well be!

What you brought is a waste of time. What are you willing to do to quit mucking with garbage and learn for yourself how to do this stuff? It won't quick and easy but it could be worth the effort.

I think we owe OP some compliments.
Code tags and error codes, all in his first post!

I think this project might be too difficult for a beginner. Especially starting with code that does not work.

What do you think state =LOW; will do for you?
Also, there is a fair chance that time=millis() should be dependent on else. But it is not here...
That tells us (helpers like the 2 above) that this code is not a good starter...

I am sorry for OP, but it is how it is...