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

How do I repeat something forever without triggering error (FORMATTED)?

Heres my script

print 'Playing Sound 1'
music.SoundId = song1 
music:play()
wait(120) 

--2--
print 'Playing Sound 2'
music.SoundId = song2
music:play() 
wait(120)

repeat

until script.Parent.Arrow.Anchored==false
end

9 comments

0

Why not just use the edit button?

0

?

0

Lua is case sensitive, it's ":Play()" not ":play()"

0

You have an edit button on every question and answer you write. Right above the remove button.

0

@M3 it worked when i played the sound, it just doesn't repeat.

0

You do not need an end for a repeat loop. You should also put a wait in the repeat loop otherwise it will go on forever and error out. Either that or move your music stuff in between the repeat and until. Also, you do not need to make two posts in a row, it will not get your question answered quicker.

0

Sorry @M3, first day on this site. so used to forums

0

@M39a9am3R Most Roblox functions/methods have a lowercase first letter equivalent. I'm pretty sure "Sound.Play" is one of them.

0

There is also an edit button on the Forums...

1 answer

You can make a while loop that goes on forever, but keep in mind anything after it won't run.

while true do
	wait(0.1) --crucial to prevent a studio crash
	--anything in here will repeat every .1 seconds
end

Another way to do this is to use renderstepped

game:GetService("RunService").RenderStepped:connect(function()
	--put code in here that you want the script to constantly check for updates
end)

1 comment

0

RunService method is assuming you're using a LocalScript.

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