# How can I make a single instrument loop through a script?

**URL:** <https://qa.fmod.com/t/how-can-i-make-a-single-instrument-loop-through-a-script/20570>\
**Category:** FMOD Studio\
**Created:** [August 20, 2023, 5:26am UTC](https://qa.fmod.com/t/how-can-i-make-a-single-instrument-loop-through-a-script/20570 "2023-08-20T05:26:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lxy1114](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@lxy1114](https://qa.fmod.com/u/lxy1114)\
**Post date:** [August 20, 2023, 5:26am UTC](https://qa.fmod.com/t/how-can-i-make-a-single-instrument-loop-through-a-script/20570/1 "2023-08-20T05:26:15Z")

</div>

How can I make a single instrument loop through a script?I have already written this, but it has no effect. Can we only use var region=markerTrack. addRegion (0, asset length, “loop”, studio. project. regionLoopMode. Looping);Do you want to loop like this, but I found looping=false on sound again

asset = getAsset(filepaths[0], o.Asset);  
var sound = track.addSound(event.timeline, ‘SingleSound’, 0, 10);  
sound.audioFile = asset;  
sound.length = asset.length;  
sound.name = o.Event;  
sound.looping = true; // This has no effect

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [August 23, 2023, 6:37am UTC](https://qa.fmod.com/t/how-can-i-make-a-single-instrument-loop-through-a-script/20570/2 "2023-08-23T06:37:51Z")

</div>

Hi,

What version of FMOD Studio are you using?

Would it be possible to see the whole script? I was able to get an instrument looping so I may be able to advise where we went differently.

---

<div class="post-metadata">

**Author:** ![lxy1114](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@lxy1114](https://qa.fmod.com/u/lxy1114)\
**Post date:** [August 24, 2023, 3:39am UTC](https://qa.fmod.com/t/how-can-i-make-a-single-instrument-loop-through-a-script/20570/3 "2023-08-24T03:39:08Z")

</div>

version: FMOD Studio 2.02.16

studio.menu.addMenuItem({  
name: “ZXM\Test Loop”,  
execute: function () {  
var event = studio.project.create(“Event”);  
event.name = “TestLoop”;  
var track = event.addGroupTrack();  
var asset = studio.project.importAudioFile(‘F:/sound/test.wav’);  
var singleInstrument = track.addSound(event.timeline, ‘SingleSound’, 0, asset.length);  
singleInstrument.audioFile = asset;  
singleInstrument.name = ‘test’;  
singleInstrument.looping = true;  
}  
});

Similar to this, it has no effect.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [August 24, 2023, 5:57am UTC](https://qa.fmod.com/t/how-can-i-make-a-single-instrument-loop-through-a-script/20570/4 "2023-08-24T05:57:19Z")

</div>

Hi,

Thank you for providing the code.

To confirm you are trying to enable looping on the instrument: [FMOD Studio | Working with Instruments - Looping Instruments](https://fmod.com/docs/2.02/studio/working-with-instruments.html#looping-instruments).

Using the provided code it worked for me. Is the script creating the event as well as the instrument the only issue is it is not looping?

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/5/585aef32c1804a2ee1efe1024043cc78ad0ca290.png)
