Practice it by playing it as slowly as needed to attain as close to 100% accuracy as possible (no perceivable mistakes).
Use a metronome.
Once you master it at a given slower tempo, speed it up until it becomes a challenge again and practice at the faster tempo until you master it at that tempo.
Repeat this process until you can actually achieve 100% accuracy at a slightly faster than normal tempo
, then you will have it down.
If you practice at a tempo where you are consistently making mistakes, you will not be developing the correct muscle memory.
Instead you will be ingraining your tendency to make mistakes.
Be patient.
Some passages or pieces are more difficult and take time to master.
Good luck.
music.stackexchange.com/users/16897/Rockin Cowboy
Think more about what can happen over the course of days rather than one day.
Work on something else musical or (perhaps better) go do something completely different like go for a jog or a walk.
Something happens when you work hard on something, then go away from it (or sleep) and come back to it.
(Maybe work on it a bit before you go to bed, then again in the morning.)
Whatever you do don't force it.
You can only learn at your own pace.
If you're otherwise having difficulty with the figure, try breaking it into smaller pieces and getting the portions right before putting them together.
You may be trying to get to performance level before you're ready.
You don't want that "forcing it and my hand hurts" quality to be in the playing, whatever the style is.
music.stackexchange.com/users/944/vjones
IMO the best way to learn a repetitive part is to play it every day, starting from low bpm.
When you feel comfortable then increment the bpm.
But, after all, it's only a matter of time, and patience.
music.stackexchange.com/users/24544/adellinho
You're going to need mnemonics.
You need to have a mental picture of some sort that you can hang the notes on.
It could be a story, it could be some symbols representing formal structure -- etc.
I read somewhere that one needs to put something into short-term memory repeatedly so that the item can be recalled comfortably, at the person's speed.
The point of the slow practice is to eliminate tension while you build fluency.
music.stackexchange.com/users/19678/aparente001
I'll address the issue of pain from a repetitive piece since the other answers didn't, although I agree with them about slowing down to gain accuracy.
You have muscles in your fingers and arms that need strengthening just like for any physical activity.
Pain is your body's way of telling you to back off a bit.
It helps to go back to basics.
Make sure you have a bench at the proper height, that you aren't bending your wrists, and you're holding your fingers loosely cupped, not tightly flexed or cramped.
Pay extra close attention to getting the fingering right.
If it's not written for you, write it down yourself with a pencil in key places.
When you feel pain, stop.
Stretch your fingers gently.
Wait until the pain subsides, plus a little longer, then try again.
As you build up your muscles, and build up your speed, and focus on proper positioning and fingering, you'll see your endurance increase.
People in good shape can play all day, with short breaks, but it took them a while to get to that point.
music.stackexchange.com/users/9981/Karl Bielefeldt
I tried to just bang it out and keep playing over and over to get the muscle memory but it feels like its not coming along and its just hurting my hand to spam it out. I've only been playing for 5 min but still. Is it just a matter of time? Should I perhaps play it multiple times per day instead of one 20-30 min session spent on learning?
What is the best way to learn a repetitive part in a piece?
music.stackexchange.com
<piano><practice>
music.stackexchange.com/questions/39247
music.stackexchange.com/users/24519/dmscs
Practice it by playing it as slowly as needed to attain as close to 100% accuracy as possible (no perceivable mistakes). Use a metronome.  Once you master it at a given slower tempo, speed it up until it becomes a challenge again and practice at the faster tempo until you master it at that tempo.  Repeat this process until you can actually achieve 100% accuracy at a slightly faster than normal tempo , then you will have it down. If you practice at a tempo where you are consistently making mistakes, you will not be developing the correct muscle memory. If you practice at a tempo where you are consistently making mistakes, you will not be developing the correct muscle memory.  IMO the best way to learn a repetitive part is to play it every day, starting from low bpm. When you feel comfortable then increment the bpm. The point of the slow practice is to eliminate tension while you build fluency.    Be patient.  Some passages or pieces are more difficult and take time to master.  Think more about what can happen over the course of days rather than one day. Work on something else musical or (perhaps better) go do something completely different like go for a jog or a walk.  Something happens when you work hard on something, then go away from it (or sleep) and come back to it. (Maybe work on it a bit before you go to bed, then again in the morning.) Whatever you do don't force it.  You can only learn at your own pace. But, after all, it's only a matter of time, and patience.  Gradually increase the pace until you feel more comfortable. It's more effective to practice regularly at a pace where you still make mistakes. It is up to you to learn things at your own pace and in your own way.
Practice at a slow tempo until you feel relaxed, then raise the beat per minute. With slow practice, you are able to gain better control while you are also reducing the burden of stress. It's much easier to develop accurate muscle memory if you practice regularly at a pace where you're still making mistakes. Every time you practice,You develop the muscle memory to be able to play the notes faster. It is necessary to work steadily at this pace because you can eventually achieve your goal of full expansion. Patience is a virtue. In terms of a difficulty level of learning, passages or pieces, there are some that are harder and more demanding. You have to discover things on your own time and in your own way. Once that is overcome, it is just a matter of time and patience. If you are having trouble with the figure, break it down the proportions. Performance is usually for a goal, not readiness. If I don't like it, I don't have to do it. You need to have a mental picture of some sort that you can hang the notes on. It could be a story, it could be some symbols representing formal structure -- etc. Pain is your body's way of telling you to back off a bit. It helps to go back to basics. Make sure you have a bench at the proper height, that you aren't bending your wrists, and you're holding your fingers loosely cupped, not tightly flexed or cramped. As you build up your muscles, and build up. your speed, and focus on proper positioning and fingering, you'll see your endurance increase.