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

Why doesn't this script loop the sound?

Asked by 10 years ago

Hello, please can someone tell me what I have done wrong with line 16? I want it to loop the above soundtrack 10 times but it only plays once.

This is the error message: Workspace.Part.Script:18: attempt to call global 'loop' (a nil value)

Thank you.

BoolValue = script.Parent.Parent.EmergencyLight1.Toggle
sound1=game.Workspace.Sound1
sound2=game.Workspace.Sound2
sound3=game.Workspace.Sound3
sound4=game.Workspace.Sound4 

function onClick()
    if BoolValue.Value == false then
        BoolValue.Value = true
        print(BoolValue.Value)
    sound1:Play()
wait(3)
sound2:Play()
wait(5)
sound3:Play()
loop(10) -- Why doesn't this loop? It just waits then plays the other sound
wait(85)
sound4:Play()
    else BoolValue.Value = false
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

3 answers

Log in to vote
3
Answered by
ImageLabel 1541 Moderation Voter
10 years ago

I don't think (loop(10) is the right method)

Pre-set their "Looped" bool to true and play them, then play the fourth sound after the desired time.

0
Worked perfectly fine. Thanks! I just did sound3:Play() wait(10) sound3:Stop() :) WelpNathan 307 — 10y
Ad
Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

You have never defined loop. (Hence it is nil; you are calling it with a value of 10; but you cannot call nil, hence your error).

Why would this do anything in particular?

Sounds do not have any API to play them a certain number of times. You can loop using the Looped property but this does not let you configure a number of loops. You must manage that yourself, by stopping it after a certain amount of time, e.g., 10 * lengthofsound seconds.

Log in to vote
0
Answered by 10 years ago

There is basicly no scripting to do it. You put on loop on the sound id. If you talking about something else please tell me.

Answer this question