PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

DidLoop

Event that fires whenever the Sound loops. Returns soundId and numOfTimesLooped, giving the contentID of the sound and the number of times looped respectively.

When the Sound is stopped the looped counter resets meaning the next DidLoop event will return 1 for numOfTimesLooped.

Parameters

Name Type Default Description

The Sound/SoundId of the Sound that looped.

int

The number of times the Sound has looped.


Code Samples


Loop a Number of Times

This code sample includes a function that will play a sound and allow it to loop for a given number of times before stopping it.

local function loopNTimes(sound, numberOfLoops)
	if not sound.IsPlaying then
		sound.Looped = true
		local connection = nil
		connection = sound.DidLoop:Connect(function(soundId, numOfTimesLooped)
			print(numOfTimesLooped)
			if numOfTimesLooped >= numberOfLoops then
				-- disconnect the connection
				connection:Disconnect()
				-- stop the sound
				sound:Stop()
			end
		end)
		sound:Play()
	end
end