Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Making a sound play in intervals?

I have this sound placed within a player, and I'd like to have it played in set intervals so that it either isn't always repeating back to back, or that it doesn't only play just once. but I can't seem to find any information on this subject.

Something I've tried is increasing the Time Length in hopes of just increasing the audio length (so that nothing is played in that extra duration) so that it will then proceed to replay the sound again once the extra duration is up. This script is inside of the sound:

script.Parent:Play()
script.Parent.TimeLength = 20

7 comments

0

Do you know how to script, or just how to copy and paste? I'd suggest looking into how to write a loop.

0

Come on man, at least link a reference page. You're here to help, not to bully! (:

1

I'm not here to act as a substitute for your brain or reasonable prior research. Failing to adequately learn the language is laziness, not misunderstanding.

0

Oof alright. So dismiss anyone who may have a learning or cognitive function disability. You wouldn't make the greatest teacher, and I'm grateful you didn't choose to pursue that career path. Though that's off topic. I appreciate your trying to help as someone such as you, I could only expect their best from.

0

lol

0

A learning disability is not going to make me give you answers. You either learn, or you don't learn. If you have a learning disability, you just have to work harder to learn - The fact that you find something more difficult does not excuse you from learning, it just means you picked the short straw.

0

sheesh so snarky

1 answer

Although the people who commented are right, you do need to learn, I will give you an easy pass and provide you with something to loop it. I will however educate you on it.

local sound = script.Parent --  Makes it easier to interact with the item by declaring it a local variable
repeat
	sound:Play() -- We're playing the sound
	absoluteLength = sound.TimeLength -- Total Sound Length
	changedLength = sound.TimeLength/sound.PlaybackSpeed -- Gets new timelength from the PlaybackSpeed since PlaybackSpeed changes how quick or slow the audio finishes
	randomWait = math.random(changedLength,changedLength*5) -- Randomly picks an interval from changedLength to 5 times that of changedLength
	wait(randomWait) -- All infinite loops should have a wait() or your game freezes, used the variable "randomWait" to initiate the interval wait
until 1==0 -- Having it repeat until 1==0 makes an infinite loop

But yeah, hopefully this helps and educates you.

This discussion is preserved as it was. New answers, comments, and votes are closed.