Read this thread. (Perhaps not all of it, though that would be a good tutorial. )
Next, please go and read the instructions, then go back and modify your post using the "More --> Modify" option to the bottom right of the post, to mark up the code (but it always needs to be the complete code) as such so we can examine it conveniently and accurately. Please do not post a ".ino" file as an attachment - that would mean that you are expecting people to actually load it to their IDE to look at it and that is extra unnecessary labour. In fact, attachments do not always show properly on different operating systems.
If you do not mark it up as code, the code you post could well be garbled and is frequently anything but easy to read.
Note: Also mark up any data in the same way. This includes error output that you get from the IDE.
And - before you post any code, use "Auto Format" in the Tools menu of the IDE to properly present the code.
Try and avoid unnecessary white space (blank lines). You should only use these to separate functional blocks of code.
You cannot run two loops on a Arduino Mega processor, you need a processor with a operating system or multiple kernels. One possibility is the ESP32, but it requires some process configuration to work.
There are other ways to do multiple jobs on the Mega processor.