Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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
0
Why not just use the edit button? M39a9am3R 3210 — 8y
0
? ethanlaj 5 — 8y
0
Lua is case sensitive, it's ":Play()" not ":play()" M39a9am3R 3210 — 8y
0
You have an edit button on every question and answer you write. Right above the remove button. M39a9am3R 3210 — 8y
View all comments (5 more)
0
@M3 it worked when i played the sound, it just doesn't repeat. ethanlaj 5 — 8y
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. M39a9am3R 3210 — 8y
0
Sorry @M3, first day on this site. so used to forums ethanlaj 5 — 8y
0
@M39a9am3R Most Roblox functions/methods have a lowercase first letter equivalent. I'm pretty sure "Sound.Play" is one of them. Link150 1355 — 8y
0
There is also an edit button on the Forums... Link150 1355 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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)
0
RunService method is assuming you're using a LocalScript. M39a9am3R 3210 — 8y
Ad

Answer this question