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

How can i make a sound play after some time?

Basically, i'm gonna make something thats called King Headless, He makes an evil laugh every 20 to 15 seconds, What do i need to do to make that possible?

while true do

wait(0.5)

script.Parent.EvilLaugh:Play()


end

Please Write your examples in answers, i do not understand through comments.

3 answers

✓ Accepted answer
while true do
wait(math.random(15,20)

script.Parent.EvilLaugh:Play()
script.Parent.EvilLaugh.Ended:Wait()

end

Hope This Helps!

1 comment

0

Make sure to put a 'math.randomseed(tick())' in the first line of code, It makes the randomness even more random

To make your cooldown from 15-20 seconds you'll need to change the wait() time.

local sound = script.Parent:WaitForChild("EvilLaugh")
while true do
	wait(17.5) -- average of 15 and 20
	sound:Play()
	wait(sound.TimeLength)
	sound:Stop()
end

The 'wait(sound.TimeLength)' bit will make it so that the sound will stop after it's done playing.

This is quite simple, you’re using the correct loop, but I’d use repeat as it feels a little bit cleaner.

local EvilLaugh = script.Parent.EvilLaugh --//Get used to reference variables, they help juristically
repeat wait(25) --// time between each “laugh”; before the next run.
   EvilLaugh:Play()
      wait(EvilLaugh.TimeLength)
   EvilLaugh:Stop() --// Extra precaution if the sound doesn’t stop
until --// you should probably provide a conditional statement to break the loop as if something breaks have by the loop processing nothing forever.

Hope this helps!

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